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:
“Computer mediation seems to bathe action in a more conditional light: perhaps it happened; perhaps it didnt. Without the layered richness of direct sensory engagement, the symbolic medium seems thin, flat, and fragile.”
—Shoshana Zuboff (b. 1951)
“A sentence is made up of words, a statement is made in words.... Statements are made, words or sentences are used.”
—J.L. (John Langshaw)