in reply to Re: Inserting into an array while stepping through it
in thread Inserting into an array while stepping through it
Suppose my orginal array is
( a, aba, aaa, aca, bbb, abc )
Suppose my trigger for change is when the elements of the line are all the same - "aaa".
So index goes 0, 1, 2
At index = 2 I splice in 3 lines to replace it, so my array now looks like
( a, aba, replacement1, repalcement2, replacement3, aca, bbb, abc)
Next iterator is index=4, which gives me "replacement2" instead of "aca".
If I'm using something like:
(which I am) and it can return a list the size of which is going to depend on context (such a hw previous eleements of the array had been treated - think of an order form where discount is by group and volume), then the juggling of the index counter is pretty hairy. I've tried this. The resulting code is very far from elegnant and my test harness easily "breaks" it, not least of all when the returned value is an empty list and the primary array gets shrunk. The iterator misses a line! However the worst case is when the replacement is two elements and the second element is a copy of the original. (Think about that!)splice(@array, $i, 1, func($array[$i]);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Inserting into an array while stepping through it
by runrig (Abbot) on Jun 13, 2003 at 15:04 UTC |