Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: canonical doc explaing need for "eval { ... } or do {...}" construct

by ikegami (Patriarch)
on May 11, 2022 at 14:18 UTC ( [id://11143794]=note: print w/replies, xml ) Need Help??


in reply to canonical doc explaing need for "eval { ... } or do {...}" construct

Since 5.28, it doesn't matter.

Before, especially before 5.14, $@ could get clobbered, so if eval { ... ; 1 } was more reliable.


There was a time where it was possible for $@ to get cleared or replaced before eval returned.

package Mod { DESTROY { eval { } } } eval { my $x = bless( {}, "Mod" ); die( "xxx\n" ); }; print $@ || "[undef]\n";
$ 5.12t/bin/perl a.pl [undef]

This has been fixed.

$ 5.14t/bin/perl a.pl xxx

So, using eval { ...; 1 } and checking the result of eval was more reliable. And it was promoted as the more reliable solution for this reason. There was an attempt to fix in 5.14, but edge cases were only fixed in 5.28.


Updated to cover edge cases found later, as per choroba's reply.

Replies are listed 'Best First'.
Re^2: canonical doc explaing need for "eval { ... } or do {...}" construct
by choroba (Cardinal) on May 11, 2022 at 16:22 UTC
    > Since 5.14, it doesn't matter.

    Have you followed the links provided in this thread? E.g. Re: Bug in eval in pre-5.14. 5.14 is not safe.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      I had not. Thanks. I have adjusted my post.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-25 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found