http://qs321.pair.com?node_id=172218


in reply to Re: map, grep, for, foreach
in thread map, grep, for, foreach

As far as I can tell for and foreach are not the same. The do the have the same functionality but due to the internals of perl they execute differently (something to do with lookup tables I believe, but not sure :P ).

A foreach runs far faster than for.

I converted one of my data mangling scripts to foreach loops and the whole thing sped up 35%. Ever since I have stopped believing what they say about for and foreach being the same and only ever use foreach if there is a choice between the two.