"Better use foreach instead of for, when you iterate over an array."
Why, they do the exact same thing:
print $_ for qw(foo bar baz);
print $_ foreach qw(foo bar baz);
$ perl -MO=Deparse foo.pl
foreach $_ ('foo', 'bar', 'baz') {
print $_;
}
foreach $_ ('foo', 'bar', 'baz') {
print $_;
}
foo.pl syntax OK
I will admit that i tend to use foreach when i
iterate over a 'collection', but never
hardly ever (never say never...) when iterating over
arrays. As a matter of fact, i have really started to favor
for over foreach because foreach
is just too wordy. But, consitency is alway king. :) | [reply] [d/l] |