Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: looking for a good idiom: return this if this is true

by Zaxo (Archbishop)
on Mar 05, 2005 at 18:38 UTC ( [id://436939]=note: print w/replies, xml ) Need Help??


in reply to Re: looking for a good idiom: return this if this is true
in thread looking for a good idiom: return this if this is true

The || operator is the high priority logical or, so if thatroutine() evaluates false, die is evaluated before return is.

Update: Oops, I misunderstood your objection, which is correct:

$ perl -Mstrict -we'sub bar {"baz"} sub foo {eval{return bar() || die} +; "quux"} print foo()' quux$
If the eval return was effective in the foo() call, should have printed "baz".

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^3: looking for a good idiom: return this if this is true
by borisz (Canon) on Mar 05, 2005 at 18:49 UTC
    Thats clear to me, but I do not understand the other part: The question is how to return a value, if it is true and continue otherwise.
    sub that { 5 } sub xx{ eval { return that() || die }; 1 } print xx; __OUTPUT__ 1
    But the op wants 5 and that the part outside the eval is not executed expect when that is false.
    Boris

Log In?
Username:
Password:

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

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

    No recent polls found