in reply to Re: Memory /speed questions
in thread Memory /speed questions

Using large lists in a foreach, ie. foreach (1..10000) { }.

Whilst this used to be so, in recent versions of perl, (5.6.x/5.8.x) it is no longer so.

Neither for (1 .. 10_000_000) { ... }

nor  for ( @a ) { ... }

will consume an (extra) memory as they are implemented as iterators. In the latter case, the control variable or $_ is aliased to the array element, so even if @a is huge, no additional memory is consumed by the construct.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller