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

Re: Is it safe to append to the array you are iterating over

by Discipulus (Curate)
on Mar 15, 2013 at 09:00 UTC ( #1023643=note: print w/ replies, xml ) Need Help??


in reply to Is it safe to append to the array you are iterating over

i found this very interesting.. it is incredible after more then 10 years using Perl, discover 'new' point of view about some simple as a  foreach (@array) loop.

++ to Re: Is it safe to append to the array you are iterating over and Re: Is it safe to append to the array you are iterating over (yes)

I'm happy to see that, once again,Perl is doing it correctly: it is a logical operetion append to a list while iterating over it. Other operations are confusing.

May be worth to add some words to Perldoc: "...get very confused if you add or remove elements within the loop body (unless you merely push something at the end),....".

L*

there are no rules, there are no thumbs..


Comment on Re: Is it safe to append to the array you are iterating over
Select or Download Code
Re^2: Is it safe to append to the array you are iterating over
by DrWhy (Chaplain) on Mar 15, 2013 at 22:53 UTC
    I would not be in favor of making this documentation change, but since this is effectively adding to the list of supported features of the language, turning an implementation detail into a officially supported behavior, I wouldn't do this without adding tests for it in the perl test suite, and getting approval from whoever gives approval for behavioral changes to the language.

    That is, this change should be treated as not just a 'doc fix' but a new feature.

    --DrWhy

    "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2014-07-29 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (225 votes), past polls