in reply to Inserting into an array while stepping through it
Update: removed parens in $i += ( @in ); though it seems to work.my @a = qw( 1 3 2 4); # NOT TESTED MUCH $i = 0; while ($i < @a ) { if ($a[$i] == 2) { my @in = mysub(whatever); splice @a, $i, 1, @in; $i += @in ; } else { $i++; } } print "@a\n"; sub mysub { # whatever return ( qw(9 2 9)); # always return an array, even if only 1 element }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Inserting into an array while stepping through it
by Anonymous Monk on Jun 13, 2003 at 12:22 UTC | |
by zakb (Pilgrim) on Jun 13, 2003 at 14:11 UTC |