in reply to Why <c>eval {...};if ($@) { die $@ } else { ...</c> ???
Well, they could have written that as
my $res = eval { something(...); }; die $@ if $@; do_something_more(...);
But! compare
use Carp; $SIG{__DIE__} = \&Carp::confess; my $res = foo(); print "ok\n"; sub foo { local $SIG{__DIE__}; die "BANG!"; } __END__ BANG! at - line 8.
and
use Carp; $SIG{__DIE__} = \&Carp::confess; my $res = eval { foo() }; die $@ if $@; print "ok\n"; sub foo { local $SIG{__DIE__}; die "BANG!"; } __END__ BANG! at - line 9. at - line 4
I guess it's not cargo-culting... the eval BLOCK and subsequent die provides an additional frame for Carp to consider.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why eval {...};if ($@) { die $@ } else { ...???
by Jenda (Abbot) on Apr 03, 2009 at 22:55 UTC | |
by shmem (Chancellor) on Apr 03, 2009 at 23:19 UTC | |
by Jenda (Abbot) on Apr 03, 2009 at 23:43 UTC | |
by shmem (Chancellor) on Apr 04, 2009 at 00:04 UTC | |
by Jenda (Abbot) on Apr 04, 2009 at 00:45 UTC |