http://www.perlmonks.org?node_id=351400


in reply to Why no $@ after eval? Bug?

They do not produce different results. Look:

$ perl -e 'eval { map { $_++ } 1 };' $ perl -e 'eval { map { $_++ } 1 }; print $@;' Modification of a read-only value attempted at -e line 1. $ perl -e ' map { $_++ } 1 ' Modification of a read-only value attempted at -e line 1.

In the first attempt, you have your code in an eval block, so the error is stored in $@.

Now, why isn't it getting printed?
I'm assuming it's because rmap evaluates the code it is being handed my @got = eval { $self->call(); }; so it is overwriting the value of $@ and thus when your eval block gets out it doesn't print the error message. I would assume that calling evals inside of eval could get messy.

Someone cares to elaborate about eval inside of eval? for example, why doesn't this:

$ perl -e '$n = q/eval { die;}; print "1: $@"/; eval {$n}; print "2: $ +@"'
print out "1: Died at (eval 1) line 1." ?


He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Chady | http://chady.net/

Replies are listed 'Best First'.
Re: Re: Why no $@ after eval? Bug?
by hv (Prior) on May 07, 2004 at 11:26 UTC

    Someone cares to elaborate about eval inside of eval? for example, why doesn't this:

    $ perl -e '$n = q/eval { die;}; print "1: $@"/; eval {$n}; print "2: $ +@"'
    print out "1: Died at (eval 1) line 1." ?

    Mainly because you left out "-w", which would have helped point you to the fact that you used eval {$n} instead of eval $n. Making that change gives you the output you'd expect.

    Hugo