The array has lots of data and I need to delete two elements.
Below is the code snippet I am using,
my @array = (1,2,3,4,5,5,6,5,4,9);
my $element_o
if you change
my @del_indexes = grep { $arr[$_] eq 'foo' } 0..$#arr;
to
my @del_indexes = reverse(grep { $arr[$_] eq 'foo' } 0..$#arr);
This avoids the array renumbering issue by removing elements from the back of the array first. Putting a splice() in a foreach loop cleans up @arr. Relatively simple and readable...
foreach $item (@del_indexes) {
splice (@arr,$item,1);
}