http://qs1969.pair.com?node_id=736213


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