Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: eval and return values

by JavaFan (Canon)
on Jan 14, 2009 at 13:22 UTC ( #736227=note: print w/replies, xml ) Need Help??


in reply to eval and return values

I'd write that as:
my $foo; eval {$foo = bar->something(); 1} or die "eval failed ($@)"; $foo;
First, I don't 'my' $foo inside the block. Second, an eval may fail, yet leave $@ false (because of 'end of scope' effects). So you should make sure that on success, the eval returns a defined value, and check the return value of the eval.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://736227]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2023-06-07 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (29 votes). Check out past polls.

    Notices?