in reply to delete multiple occurrences
This uses an array slice greping the indices of @b that satisfy the criteria.
use strict; use warnings; my @a = ( 1, 9, 3, 4, 5, 6, 7, 2, 4, 3 ); my @b = qw{ x y z z a z z z b c }; my @aNew = @a[ grep { ! $_ || $b[ $_ ] ne q{z} || $b[ $_ - 1 ] ne q{z} } 0 .. $#b ]; print qq{@aNew};
The output.
1 9 3 5 6 4 3
I hope this is of interest.
Cheers,
JohnGG
|
|---|