Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How foreach loops decide what to iterate through

by ysth (Canon)
on Feb 15, 2009 at 18:50 UTC ( [id://743953]=note: print w/replies, xml ) Need Help??


in reply to How foreach loops decide what to iterate through

In principle, foreach iterates over a list that is constructed before the looping begins, so you should have no concerns about making extra work for each iteration by having a complex expression for the list being iterated over.

In practice, iterations over a range (foreach ($x .. $y)) or an array (even one built on the fly: foreach (@{[ sort @x ]})) are optimized to not need to load the full list ahead of time. Since this optimization shouldn't introduce differences in behaviour, what you are seeing with a push in the loop is a bug.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://743953]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-25 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found