in reply to Re^3: Strange behavior: passing $1 to AUTOLOAD
in thread Strange behavior: passing $1 to AUTOLOAD
Aha! But what if you don't want to create a lexical variable that lives any longer than necessary? Well, you could use a bare block:
{ my $error = $!; $log->error($error) }
But then what if you want the return value from the method? Well, you could use do:
my $return = do { my $error = $!; $log->error($error) };
That's probably the sane way to handle it. But what if you're not sane? Then we can have some fun!
my $return = $log->error(${ \(my $e = $!) });
Update: another fun way that never even makes the lexical variable:
my $return = $log->error(@{[$!]});
|
|---|