[oak perl] my operator question

Zed Lopez zed.lopez at gmail.com
Thu Mar 10 13:15:56 PST 2005


Mark Bole wrote:
>Actually, in the camel book, "for (foreach)" is not even documented as a 
>legal statement modifier, only "if", "unless", "while" and "until".

True for 2d edition, not for 3d:

ch. 4 section 1 Simple Statements

Any simple statement may optionally be followed by a single modifier,
just before the terminating semicolon (or block ending). The possible
modifiers are:

if EXPR
unless EXPR
while EXPR
until EXPR
foreach LIST

The if and unless modifiers work pretty much as they do in English:

$trash->take('out') if $you_love_me;
shutup() unless $you_want_me_to_leave;

The while and until modifiers evaluate repeatedly. As you might
expect, a while modifier keeps executing the expression as long as its
expression remains true, and an until modifier keeps executing only as
long as it remains false:

$expression++ while -e "$file$expression";
kiss('me') until $I_die;

The foreach modifier (also spelled for) evaluates once for each
element in its LIST, with $_ aliased to the current element:

s/java/perl/ for @resumes;
print "field: $_\n" foreach split /:/, $dataline;


More information about the Oakland mailing list