Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Different result for 'foreach' vs 'while shift' arrayref

by sundialsvc4 (Abbot)
on Apr 18, 2014 at 13:02 UTC ( #1082759=note: print w/ replies, xml ) Need Help??

in reply to Different result for 'foreach' vs 'while shift' arrayref

Incidentally, is there documentation of the behavior of foreach if the contents of the array are volatile during the loop?   And of unshift vs. push in such a frightful but-it-happens scenario?

Comment on Re: Different result for 'foreach' vs 'while shift' arrayref
Re^2: Different result for 'foreach' vs 'while shift' arrayref
by kcott (Abbot) on Apr 19, 2014 at 06:47 UTC

    Yes. See the "Foreach Loops" section of "perlsyn - Perl syntax":

    "If any part of LIST is an array, foreach will get very confused if you add or remove elements within the loop body, for example with splice. So don't do that."

    -- Ken

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2015-07-07 13:34 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (88 votes), past polls