Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1023515]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 10:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found