Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: "or die" versus "|| die"

by davidrw (Prior)
on Jun 24, 2005 at 15:02 UTC ( [id://469730]=note: print w/replies, xml ) Need Help??


in reply to "or die" versus "|| die"

I think in a lot of cases it doesn't matter (especially if die'ing), but there is a difference in precedence. perldoc perlop shows that || is higher than = and some other operators, and or has the lowest pecedence.

I've had cases where || return needed to be changed to or return so that Devel::Cover wouldn't complain about never getting a true value for the other half of the construct.

Replies are listed 'Best First'.
Re^2: "or die" versus "|| die"
by davido (Cardinal) on Jun 24, 2005 at 15:44 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.


    Dave

      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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://469730]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2024-04-19 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found