Conditional Statements
if ( expr ) block if ( expr ) block else block if ( expr ) block elsif ( expr ) block ... else block unless ( expr ) block unless ( expr ) block else block unless ( expr ) block elsif ( expr ) block ... else blockwhere block is a sequence of one of more Perl statements surrounded by braces.
The controlling expressions are evaluated in a boolean context: The numeric value 0, the strings "" and "0", and the undefined value undef are false, all other values are true. This means that the strings "0.0", "00", "-0", and "0 but true" are all true, even though their value would be converted to 0 in a numeric context; values like these are sometimes used when a successful operation needs to return 0.
Evaluating an empty array or hash in scalar context yields undef, which is false. Therefore, the following example prints "a is empty":
my @a=; unless (@a) { print "a is empty" }Read more about this topic: Perl Control Structures
Famous quotes containing the words conditional and/or statements:
“The population of the world is a conditional population; these are not the best, but the best that could live in the existing state of soils, gases, animals, and morals: the best that could yet live; there shall be a better, please God.”
—Ralph Waldo Emerson (18031882)
“In so far as the statements of geometry speak about reality, they are not certain, and in so far as they are certain, they do not speak about reality.”
—Albert Einstein (18791955)