Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

splice

Removes and/or replaces elements in an array, returning the removed elements.

Removes $length elements starting at $offset from @array, optionally replacing them with @replacements, and returns the removed elements. Negative $offset counts from the end of the array. If $length is omitted, removes everything from $offset onward. A negative $length leaves that many elements at the end. Replacement arrays are flattened. The array is rebuilt in place.

Synopsis

my @removed = splice @array, $offset;
my @removed = splice @array, $offset, $length;
my @removed = splice @array, $offset, $length, @replacements;
splice @array, 0, 0, @prepend;    # insert at beginning

See Also

push, pop, shift, unshift, delete