Think lists and iterators. The length may not ever be evaluated in Perl - it's more complicated than that, and you don't need to know. :)
Take a trawl through the STL and you will find equivelent constructs to foreach: for_each in <algorithm> for example.
Update: just to make it a little clearer - Perl generates the list for the foreach "up front" before the first iteration of the loop. If your loop is over an array, the list is the array. If the loop is over something like keys of a hash or lines of a file a temporary list is generated.
In reply to Re: foreach to for
by GrandFather
in thread foreach to for
by tricolaire
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |