in reply to Inserting into an array while stepping through it

You can do that by taking the indexes in reverse order. Added slots in the array move the higher indexes, but leave the lower ones alone.

for ( reverse(0..$#array) ) { if ( the_condition($array[$_]) ) { splice @array, $_, 1, the_sub($array[$_]) } }

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Inserting into an array while stepping through it
by Anonymous Monk on Jun 13, 2003 at 12:02 UTC
    Yes, Zaxo, I know that doing backwards works.

    However this is part of a parser and the constraints of where it is used means that the traversal hasto be forward.