Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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
Replies are listed 'Best First'.
Re^2: Different result for 'foreach' vs 'while shift' arrayref
by kcott (Canon) 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 perusing the Monastery: (5)
As of 2015-11-27 04:16 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (717 votes), past polls