Just this week I ran into a situation where I needed to be more systematic in element removals. Reading the array section in Q&A proved to be enlightening. Note the use of splice here.
Quoting from the Q&A
my $index = 0; while ($index <= $#items ) { my $value = $items[$index]; print "testing $value\n"; if ( $value == 1 or $value == 3 ) { print "removed value $value\n"; splice @items, $index, 1; } else { $index++; } }
I tried using delete (which I thought was just for hashes) but got zero results, though the Perl ref says it's one of the methods. But maybe I'm not quite getting it.
In reply to Re: Array Processing
by bradcathey
in thread Array Processing
by Rajeshk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |