Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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.


Comment on Re: Is it safe to append to the array you are iterating over
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-12-26 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (170 votes), past polls