Boolean Conditions
Essentially, zero, null, empty-strings, or undefined values are taken to be “False”. You can find truth in all other values. Arrays and Hashes are true if they are not empty. Their elements are true if they exist and have true values.
### False ### if ("") ... if (0) ... if (undef) ... if ( @a=() ) ... ### True ### if ("hello") .... if (123) .... if ( %h=(key1=>1) ) .... ### Self-Terminating Conditions ### while (my $a = shift @array) { print $a; } # Stops when empty, $a is undef ### Complex Conditions ### if ($a && ($b || $c)) ... # And (&&) binds tighter than Or (||); ### True values are returned ### $v = 0 || 123; # returns 123 $parameter = $parameter || 'perl'; # defaults parameter to value 'perl'; ### Short Circuited ### if ( 123 || mysub() )... # Since 123 is true. mysub is not called ### Use "or" or "and" for statements ### open(FILE,$name) or die "could not open file"; # If open fails, next statement is executed open(FILE,$name) and close FILE; # Closes only if open worked.