Perl provides the &&
(logical AND) and ||
(logical OR) operators. They evaluate
from left to right testing the truth of the statement.
Example | Name | Result |
---|---|---|
| And | |
| Or | |
For example, an oft-appearing idiom in Perl programs is:
open(FILE, "somefile") || die "Cannot open somefile: $! ";
In this case, Perl first evaluates the open
function. If the value is true
(because somefile
was
successfully opened), the execution of the die
function is unnecessary and is
skipped.
Perl also provides lower-precedence and
and or
operators that are more
readable.
18.189.170.134