in reply to Re^2: Turning foreach into map?
in thread Turning foreach into map?
Foreach is faster than map if you're modifying in place. If you're using foreach to push into an array, like what's happening here, then map is going to be faster. (which is why there's the recommendation not to use map if you're not doing anything with the list generated -- you might as well have just done foreach).This is no longer the case for recent versions of perl. Now map has been optimized in void context, so if you don't do anything with the return values, it doesn't bother generating them.
In theory, the only difference between map and for/foreach now is a matter of taste/style. (I say "in theory", because I haven't benchmarked it, and sometimes the perl porters *think* they've done, isn't quite what they've done.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Turning foreach into map?
by Roy Johnson (Monsignor) on Apr 05, 2005 at 22:59 UTC | |
by Anonymous Monk on Apr 06, 2005 at 08:48 UTC |