On 12/10/2014 04:14 PM, Andy Bach wrote:


  my $ho;
  my $warning_occured = 0;
  #my $default_warn = $SIG{__WARN__};
  $SIG{__WARN__} = sub {
    $warning_occured = 1;
    warn("my: ", @_);
   };

print $ho;
  if ($warning_occured) {
      print "sent warning\n";# Code to run if a warning occured
  } else {
      print "didn't sent warning\n";# Code to run if a warning occured
      # Code to run if no warning occured
  }

I was thinking this would be a neat place to show the remaining reason for using "&" to mark a function call - it sends the current "@_" to that function, but I couldn't get it to work.

the way to do that is to modify @_ in the calling routine and then calling the sub with &. in your case it would be

    unshift @_, 'my: ' ;
    &foo ;

but you are calling warn there which may not work that way as it is builtin. for an example of &foo being used in real world code, see the source of File::Slurp. the error handling code is called with & from several places. the win there isn't just sharing the code but the return from the error handler goes back to the user's caller and not to a sub in the module.

uri


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to