in reply to foreach to for
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: foreach to for
by Limbic~Region (Chancellor) on Jun 18, 2006 at 23:18 UTC | |
by GrandFather (Saint) on Jun 18, 2006 at 23:41 UTC |