splice with map could work, but the better approach if possible would be to catch it on the front end, and filter it; you may make optimizations once you get it working for your purposes. A possible improvement would be to replace the grep with List::Util's any function.
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);
Output,
$ 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' ];

In reply to Re: Inverse slices by oodler
in thread Inverse slices by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.