Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: "or die" versus "|| die"

by davido (Archbishop)
on Jun 24, 2005 at 15:44 UTC ( #469744=note: print w/replies, xml ) Need Help??


in reply to Re: "or die" versus "|| die"
in thread "or die" versus "|| die"

Just because you're invoking die after an || or a or doesn't mean you don't have to think about precedence. Consider the following:

somesub $this, $that || die;

If you use 'or' here, you'll die upon failure of somesub (assuming it returns false to indicate failure). If you use ||, you'll die if $that is false. Big difference.


Dave

Replies are listed 'Best First'.
Re^3: "or die" versus "|| die"
by Anonymous Monk on Jun 24, 2005 at 20:30 UTC
    Just because you're invoking die after an || or a or doesn't mean you don't have to think about precedence. Consider the following: somesub $this, $that || die; If you use 'or' here, you'll die upon failure of somesub (assuming it returns false to indicate failure). If you use ||, you'll die if $that is false. Big difference.

    If you call somesub with parens, the argument list is clearer to novice coders, the notation matches what they learned in grade 6 math class, and in this case, the precedence issue disappears.

    In my experience, thinking too hard about precedence is usually a clue that you're being too tricky with your code.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://469744]
help
Chatterbox?
[Corion]: (nothing that a quick SQL update can't fix in the input data, but why did the people organizing the test not plan that test under real conditions...)

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2017-09-26 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (296 votes). Check out past polls.

    Notices?