www.perl.com
Perl Programming
Conditional Statements
  • Conditional statements provide boolean context
  • if statement controls the following block
    • if, elsif, else
    • Yes, that does say elsif. Oh well.
  • unless is opposite of if
    • Equivalent to if (not $boolean)
    • unless, elsif, else
    • There is no elsunless, thankfully.

        my ($a, $b) = (0, 1);
        if (!$a && !$b)        {print "Neither\n";} # Conventional
        if (not $a and not $b) {print "Neither\n";} # Same, but in English
        if (not ($a or $b))    {print "Neither\n";} # Same, but parentheses
        unless ($a or $b)      {print "Neither\n";} # Same, but clearest
      
Previous http://stuff.mit.edu/iap/perl/