Perls Before Swine: Reference: Boolean logic

  1. Reference
  2. Comparison operators

In case you’ve forgotten it from high school, here is the table of and, or, and exclusive or:

First Value Second Value AND OR
True True True True
True False False True
False False False False
False True False True

Perl recognizes the following characters for use in if, while, or other such blocks for determining whether and how often the block executes:

Character Meaning
&& AND
|| OR
! NOT

You can also use parentheses to force some logic to be interpreted before other logic. For example:

if ($isGod || ($isNietzsche && $godIsDead)) { … }

will act on that if block if $isGod is true, or if both $isNietzsche is true and $godIsDead is true.

  1. Reference
  2. Comparison operators