Like other programming languages, Perl supports mostly the same style of Block Statements and Loops.
if, elsif, else
print "This student is a teenager. \n";
} else { print "This student is an adult. \n";
}
Everything looks the same right? Look again. Notice the elsif. Is that a misspelling? No it is not. An else if statement in Perl is actually elsif.
Unless Statement
print "Welcome to Harry's. \n";
}
The above statement only is executed if $iAge >= 21. Basically it is performing the given operation if the statement in the unless block is False.
While Statement
print "You are too young to enter. \n";
$iAge += 1;
}
The above statement will continue to execute until $iAge is greater than or equal to 21.
Until Statement
print "You are too young to enter. \n"; $iAge += 1;
}
The above statement will also be executed until $iAge is greater than or equal to 21. This works similar to the Unless Statement in that it executes while the enclosed statement is False.
For Statement
print "Counting from 0 to 20 $iCount. \n";
}
The above statement sets $iCount to zero and executes until $iCount is less
than 21. It increments $iCount during this process. This should count from 0
to 20. Notice how you can embed scalars right into a print statement regardless
of their type.