Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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

by perlhaq (Scribe)
on Jun 24, 2005 at 18:55 UTC ( #469793=note: print w/ replies, xml ) Need Help??

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

Like others have said, you're better off sticking with "or" except for those few cases where the || is necessary for precedence reasons. Familiarize yourself with the operator precendence chart in the "perlop" manual page, print it out and tape it to your monitor if you have to in the beginning (eventually you'll know it instinctively).
The few cases were I use || instead of "or" are constructions like these:
my $var = $cgi->param('foo') || $default{'foo'}; # assign default value if none given
my $var = $cgi->param('foo') || ''; # assign empty value if none given (to avoid warnings due to undef value)
if ($verbose and $bar || $baz) { print "starting job $job_num\n" }

Comment on Re: "or die" versus "|| die"

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2015-12-01 06:52 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (795 votes), past polls