In this case,
control_expression is evaluated first for its truth value (using the same rules as always), and if true,
some_expression is evaluated next. This is roughly equivalent to
except that you don't need the extra punctuation, the statement reads backwards, and the expression must be a simple expression (not a block of statements). Many times, however, this inverted description turns out to be the most natural way to state the problem. For example, here's how you can exit from a loop when a certain condition arises:
See how much easier that is to write? And you can even read it in a normal English way: "last line if it begins with From."
Other parallel forms include the following:
exp1; # like: unless (
exp1; # like: while (
exp1; # like: until (
All of these forms evaluate
exp1 first, and based on that, do or don't do something with
For example, here's how to find the first power of two greater than a given number:
chomp($n = <STDIN>); $i = 1; # initial guess $i *= 2 until $i > $n; # iterate until we find it
Once again, we gain some clarity and reduce the clutter.
These forms don't nest: you can't say
exp1. This is because the form
exp1 is no longer an expression, but a full-blown statement, and you can't tack one of these modifiers on after a statement.