Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: AND OR

by Zaxo (Archbishop)
on May 14, 2006 at 06:14 UTC ( #549296=note: print w/replies, xml ) Need Help??


in reply to AND OR

Additional to what Tanktalus said.

The logical operator pairs (&& and), and (|| or) only differ by their precedence. The spelled-out ones have extremely low precedence, while the symbolic ones are fairly high.

These operators are "lazy evaluated". The or op will not evaluate its right-hand term if the left evaluated true. The and op will not evaluate its right-hand term if the left evaluated false. That makes the following possible.

The logical operators can be used as concise forms of program flow control. That is often seen in error handling. An operation which returns true on success will skip an operation connected by or, so we write,

open my $fh, '<', $filename or die $!;
to handle failure to open a file, for example.

After Compline,
Zaxo

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2023-09-26 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?