in reply to For vs. Foreach
They are synonyms, and you can find that out with B::Deparse:
$ perl -MO=Deparse -e 'foreach (1..2) { }' foreach $_ (1 .. 2) { (); } -e syntax OK $ perl -MO=Deparse -e 'for (1..2) { }' foreach $_ (1 .. 2) { (); } -e syntax OK
So they produce the same optree
|
---|
In Section
Seekers of Perl Wisdom