www.perl.com
Perl Programming
Boolean Context
  • Boolean operations apply a boolean context
  • Undefined values are treated as false
  • Scalars are evaluated as booleans
    • Numbers are evaluated as true if non-zero
    • Strings are evaluated as true if non-empty
  • Lists are evaluated as booleans
    • Lists, arrays, and hashes are evaluated as true if non-empty

        my $string;
        if ($string) {
            print "A: Hello, $string.\n";
        }

        $string = "world";
        if ($string) {
            print "B: Hello, $string.\n";
        }
      

        B: Hello, world.
      
Previous http://stuff.mit.edu/iap/perl/