Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by bart (Canon)
on Mar 14, 2013 at 17:53 UTC ( #1023515=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    foreach(my @temp = @arr) {
        push @arr, 'd' if $_ eq 'a';
    ...
        push @arr, 'f' if $_ eq 'c';
        print $_;
    }
    
  2. or download this
    for(my $i = 0; $i < @arr; $i++) {
        local $_ = $arr[$i];  
    ...
        push @arr, 'f' if $_ eq 'c';
        print $_;
    }
    
  3. or download this
    foreach(() = @arr) {
       print;
    }
    
  4. or download this
    $x = () = @arr;
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-08-01 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls