Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl: the Markov chain saw
 
PerlMonks  

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

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.