Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: eval and return values

by Bloodnok (Vicar)
on Jan 14, 2009 at 12:41 UTC ( #736213=note: print w/replies, xml ) Need Help??


in reply to eval and return values

Your code wouldn't return anything since $foo is lexically re-declared in the assignment within the eval block (something that strictures would have warned you about).

I think you probably meant something like...

my $foo = eval { bar->something() }; die $@ if $@; $foo;

Update:

s/with/within/

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: eval and return values
by AnomalousMonk (Archbishop) on Jan 14, 2009 at 20:16 UTC
    ... since $foo is lexically re-declared in the assignment within the eval block (something that strictures would have warned you about).
    No, that's kosher with warnings and strictures:
    >perl -wMstrict -le "sub S { return 'Something' } my $foo = 'bar'; eval { my $foo = S() }; die $@ if $@; print qq{after eval: $foo}; " after eval: bar

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2023-05-28 12:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?