Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2014-09-21 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (172 votes), past polls