Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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 (Chancellor) 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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2018-02-20 15:55 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (271 votes). Check out past polls.