Modifiers

Any simple statement may be followed by a single modifier that gives the statement a conditional or looping mechanism. This syntax provides a simpler and often more elegant method than using the corresponding compound statements. These modifiers are:

                     statement if EXPR;
statement unless EXPR;
statement while EXPR;
statement until EXPR;

For example:

$i = $num if ($num < 50); # $i will be less than 50
$j = $cnt unless ($cnt < 100); # $j will equal 100 or greater
$lines++ while <FILE>;
print "$_
" until /The end/;

The conditional is evaluated first with the while and until modifiers except when applied to ado {} statement, in which case the block executes once before the conditional is evaluated. For example:

do {
    $line = <STDIN>;
    ...
} until $line eq ".
";

For more information on do, see Chapter 5.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.28.80