Conditionals
Beginning |
Previous |
Next
Flavors: if and unless, the Classic Form
The two possible conditionals available to the Perl weenie is
if and unless. if is probably
the most familiar, and we might inclined to use it the most, but
unless is just a negated if. For example:
$max = 100;
if ($value == $max)
{
print "Reached max value!\n";
}
unless ($value == $max)
{
print "Not yet reached max value!\n";
}
Shorthand for Conditionals
Sometimes using the obligatory braces ({}), is more than
one person can handle. For them, there is a shorthand way of doing
one-liners:
$max = 100;
print "Reached max value!\n" if ($value == $max);
&delete_officemates_files( '/home/fred') if ($num_calls > $max);
In this form, the operation comes first, followed by the
condition. Both forms read well and are easy to understand.
Beginning |
Previous |
Next
Last Modified: $Date: 1997/05/02 07:17:37 $