in reply to Removing array elements
You want the splice operator.
Incidentally, to get away with removing elements from an array in a for loop, you need to take them in reverse order:
Many of us would write that with grep: @a = grep { ! condition($_) } @a;for (reverse 0 .. $#a) { splice @a, $_, 1 if condition($a[$_]); }
You appear to be taking the set differences of two arrays. That has a well-known technique in perl:
The funny-looking @a{@a} constructions are hash slices.my (%a, %b); @a{@a} = (); @b{@b} = (); delete @a{@b}; delete @b{@a}; @a = keys %a; @b = keys %b; # or if order matters, # @a = grep {exists $a{$_}} @a; # @b = grep {exists $b{$_}} @b;
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Removing array elements
by mrpeabody (Friar) on Aug 25, 2005 at 04:43 UTC | |
by Zaxo (Archbishop) on Aug 25, 2005 at 04:47 UTC |