next up previous contents
Next: if and unless statements Up: Control Structures Previous: Basics   Contents

Combining Logical Expressions

Perl provides two operators to combine logical expressions which can be tested by its various control structures: the or (|| or or), and the and (&& or and). You can combine expressions by separating them with these operators. When you are combining more than two statements, you can either check the precedence rules outlined in the perlop manual page, or use enough parentheses to make sure that your meaning is clear.

Like most modern languages, perl only evaluates enough expressions to verify the overall truth of compound logical expressions. For example, if you are using an and to combine two logical expressions, and the first one is not true, then the second expression is never evaluated, since the overall expression must be false. Similarly, if the first expression of a compound statement containing an or is true, then the second expression need never be evaluated since the overall expression must be true.



Phil Spector 2002-10-18