Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Or Operator

by thor (Priest)
on Jul 31, 2004 at 14:27 UTC ( #378920=note: print w/replies, xml ) Need Help??


in reply to Or Operator

As was stated above, you're having problems with operator precedence. Consider the following two one-liners:
perl -le '$a = undef or 1; print $a' perl -le '$a = undef || 1; print $a'
You may have to change the single-quotes to double-quotes to get the above examples to run from the command line, depending on what platform you're on

As perlop tells us, 'or' has lower precedence than '=', while '||' has higher precedence than '='. So the first one-liner is equivalent to:

perl -le '($a = undef) or "foo"; print $a'
whereas the second one is equivalent to:
perl -le '$a = (undef or "foo"); print $a'

thor

Feel the white light, the light within
Be your own disciple, fan the sparks of will
With all of us waiting, your kingdom will come

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2016-09-25 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (470 votes). Check out past polls.