Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: && and and (well, you try searching for an answer)

by gellyfish (Monsignor)
on Sep 02, 2006 at 20:36 UTC ( [id://570888]=note: print w/replies, xml ) Need Help??


in reply to && and and (well, you try searching for an answer)

and and or were introduced as lower precedence versions of && and ||, infact their precedence is guaranteed to be lower than any other operator so you can use them in places where otherwise you would have to use additional or otherwise unnecessary parentheses to ensure the correct meaning of a statement. This is probably clearest seen in:

open HANDLE, $file || die $!;
which is almost certainly a mistake (i.e. it won't die unless $file has a false value because the || has higher precedence than the comma in the argument list.) If you want to use || you would need to use the parentheses thus:
open(HANDLE, $file) || die $!;
Whereas:
open HANDLE, $file or die $!;
works fine.

In most places it is mostly a stylistic choice of whether to use the higher priority operator and more parentheses or not.

/J\

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-28 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found