Perl Control Structures - Conditional Statements

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 block

where 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:

    Conditional love is love that is turned off and on....Some parents only show their love after a child has done something that pleases them. “I love you, honey, for cleaning your room!” Children who think they need to earn love become people pleasers, or perfectionists. Those who are raised on conditional love never really feel loved.
    Louise Hart (20th century)

    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 (1879–1955)