Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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?
[mz2255]: I'm trying to post a question to "seekers of perl wisdom" but always getting a permission denied when I want to submit. There are no links in my post...
[ambrus]: again? someone complained about this just a few days ago (although eventually they could post)
[choroba]: Can you post the question in mz2255's scratchpad?
[ambrus]: Corion, if you're here, can you check the spam filter logs to see what's triggering this time?
[ambrus]: Petroza had trouble posting yesterday, but has posted Issues Fetching URL with a variable token since.
[mz2255]: Yes, just edited the scratchpad. Not sure if I'm doing something wrong, it's my first time.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2017-10-19 15:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (255 votes). Check out past polls.

    Notices?