Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by LanX (Bishop)
on Jul 10, 2013 at 16:03 UTC ( #1043501=note: print w/replies, xml ) Need Help??


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

not a good idea!

DB<104> @arr = qw/a b c/; => ("a", "b", "c") DB<105> foreach ( "x",@arr,"y") { push @arr, 'd' if $_ eq 'a'; push @arr, 'e' if $_ eq 'b'; push @arr, 'f' if $_ eq 'c'; print $_; } => "" xabcy

better rely on orthogonal behavior!

Cheers Rolf

( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043501]
help
Chatterbox?
[Discipulus]: gee! how much rumor for a post with no content!
[Discipulus]: an almshouse more than a monastery ;=)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2017-11-23 19:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (337 votes). Check out past polls.

    Notices?