Understanding slicing will give you a handy general-purpose tool, but you are correct that splice is the right thing for this particular purpose, assuming you don't need the previous contents of @found_images:
splice(@found_images, $pics_to_find);
That deletes all images in @found_images starting at the index $pics_to_find and continuing to the end.

If you don't want to completely lose those discarded images, use

my @discarded_images = splice(@found_images, $pics_to_find);
I find it very difficult to remember the syntax of splice. I have typed 'perldoc -f slice' many times. Not that it doesn't make sense: splice is for removing a range of elements from an array and replacing them with a list, with useful default behavior if only parts of the operation are defined. So perhaps logic is enough to figure out the parameters:

The first parameter is obvious -- it's the array to operate on. Next we need to know the range of elements to remove, so that's obviously a start and length parameter pair. And wouldn't it be nice if you could leave off the length if you wanted the rest of the array? Or if you prefer, what should happen if you leave off that length parameter? The only thing that makes sense is nuking up to the end. Oh, and a negative start argument would be handy too, if you're only concerned with the right end of the array.

Finally, there's the list of elements to insert into the "spliced" portion of the array. And just one more thing -- you might need to know what the removed elements were, so it would be convenient to return them from the overall call.

It is my hope that, having typed out that rationale, I will now be able to figure it out on my own without running back to the docs. We'll see how that works...


In reply to Re: merging arrays by sfink
in thread merging arrays 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.