Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Why no $@ after eval? Bug?

by Chady (Priest)
on May 07, 2004 at 09:07 UTC ( #351400=note: print w/ replies, xml ) Need Help??


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/


Comment on Re: Why no $@ after eval? Bug?
Select or Download Code
Re: Re: Why no $@ after eval? Bug?
by hv (Parson) 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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2014-07-13 19:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (251 votes), past polls