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";
|
|---|