That deletes all images in @found_images starting at the index $pics_to_find and continuing to the end.splice(@found_images, $pics_to_find);
If you don't want to completely lose those discarded images, use
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:my @discarded_images = splice(@found_images, $pics_to_find);
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |