Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

RE: or or

by reptile (Monk)
on Jul 08, 2000 at 15:48 UTC ( #21644=note: print w/ replies, xml ) Need Help??


in reply to or or

Well, here's what the perlop manpage says:

    As more readable alternatives to && and || when used for control flow, Perl provides and and or operators (see below). The short-circuit behavior is identical. The precedence of ``and'' and ``or'' is much lower, however, so that you can safely use them after a list operator without the need for parentheses:
    unlink "alpha", "beta", "gamma" or gripe(), next LINE;
    With the C-style operators that would have been written like this:
    unlink("alpha", "beta", "gamma") || (gripe(), next LINE);

So in other words, if you said this:

unlink "alpha", "beta", "gamma" || gripe();

the third argument to unlink would be "gamma" || gripe(); that is, always "gamma" and gripe() would never be evaluated.

'or' is smarter than that. Look at C-style Logical Or and Logical or and Exclusive or on the perlop manpage. It talks a bit about why this happens.

local $_ = "0A72656B636148206C72655020726568746F6E41207473754A"; while(s/..$//) { print chr(hex($&)) }


Comment on RE: or or
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-12-18 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls