Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Possible precedence issue with control flow operator

by 1nickt (Canon)
on Jan 13, 2020 at 11:27 UTC ( [id://11111357]=note: print w/replies, xml ) Need Help??


in reply to Possible precedence issue with control flow operator

How can return fail? Perl's warning is spot-on. If you want to croak when the return value isn't true, that needs to be associated with the sub call, not the return call. Precedence takes care of that, and you can still use or if you add parens:

$ perl -Mstrict -wE'sub foo{} sub bar{return foo() or die "died"} bar( +)' Possible precedence issue with control flow operator at -e line 1.
$ perl -Mstrict -wE'sub foo{} sub bar{return foo() || die "died"} bar( +)' died at -e line 1.
$ perl -Mstrict -wE'sub foo{} sub bar{return (foo() or die "died")} ba +r()' died at -e line 1.

Hope this helps (but you already got it I reckon...)!


The way forward always starts with a minimal test.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-25 15:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found