in reply to Inverse slices
Output,use strict; use warnings; use Data::Dumper; my @skip_idx = (6,13,42,66,69); my @array = (); my @invarray = (); my $idx = -1; foreach my $str ('aa'..'zz') { ++$idx; if (grep { /^$idx$/ } @skip_idx) { # could use List::Util::any here push @invarray, $str; print "skipped '$str' (index of $idx)\n"; } push @array, $str; } print Data::Dumper::Dumper(\@invarray);
$ perl test.pl skipped 'ag' (index of 6) skipped 'an' (index of 13) skipped 'bq' (index of 42) skipped 'co' (index of 66) skipped 'cr' (index of 69) $VAR1 = [ 'ag', 'an', 'bq', 'co', 'cr' ];
|
---|