Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Bug in eval in pre-5.14

by Anonymous Monk
on Feb 10, 2016 at 17:29 UTC ( [id://1154875]=note: print w/replies, xml ) Need Help??


in reply to Bug in eval in pre-5.14

Sorry to heat up this stale topic, but I've just been bitten by this:

#!/usr/bin/perl use Modern::Perl '2015'; use Try::Tiny; sub foo { try { say 'foo try'; die; return 'try'; } catch { say 'foo catch'; return 'catch'; }; say 'foo outer'; return 'outer'; } sub bar { eval { say 'bar try'; die; return 'try'; } or do { say 'bar catch'; return 'catch'; }; say 'fos outer'; return 'outer'; } say 'begin'; my $r = foo(); say $r; say "########"; my $s = bar(); say $s; say 'end';

So there is a subtle difference between eval ... or do and Try::Tiny: in the latter, return doesn't mean what you think it means even in the catch block.

In hindsight, it's obvious, and it is even documented explicitly, still, this behavior makes Try::Tiny slightly more inconvenient.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-28 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found