The if Statement and Relational Operators

The if/else statement looks pretty much like the C version of the if/else statement:

if (condition) {
    # body of the if 
}

and

if (condition) {
    # body of the if 
} else {
    # body of the else 
}

The expression must be enclosed in (), and most of the relational operators are the same. About the only difference is that fact that the curly braces are required. In other words, the following is illegal:

if ($size == 20) 
    print "Size is 20\n";     # Illegal –– no {}

The elsif Statement

The elsif statement is a shorthand for “else if.” For example:

 if ($size == 1) { # operators running when $size is equal to 1 } elsif ($size == –1) { # operators running when $size is equal to –1 } elsif ($size == 0) { # operators ...

Get Perl for C Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.