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

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

by BrowserUk (Pope)
on Mar 14, 2013 at 17:49 UTC ( #1023514=note: print w/replies, xml ) Need Help??

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

You can easily make that safe by substituting a list of indexes for the actual items:

my @arr = qw/a b c/; foreach ( 0 .. $#arr ) { $_ = $arr[ $_ ]; push @arr, 'd' if $_ eq 'a'; push @arr, 'e' if $_ eq 'b'; push @arr, 'f' if $_ eq 'c'; print $_; } print "\n";

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2016-10-21 10:30 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (288 votes). Check out past polls.