- splice ARRAY or EXPR,OFFSET,LENGTH
- splice ARRAY or EXPR,OFFSET
- splice ARRAY or EXPR
Removes the elements designated by OFFSET and LENGTH from an array, and replaces them with the elements of LIST, if any. In list context, returns the elements removed from the array. In scalar context, returns the last element removed, or
undefif no elements are removed. The array grows or shrinks as necessary. If OFFSET is negative then it starts that far from the end of the array. If LENGTH is omitted, removes everything from OFFSET onward. If LENGTH is negative, removes the elements from OFFSET onward except for -LENGTH elements at the end of the array. If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is past the end of the array, Perl issues a warning, and splices at the end of the array.
The following equivalences hold (assuming
$[ == 0 and $#a >= $i)
Example, assuming array lengths are passed before arrays:
Starting with Perl 5.14,
splicecan take scalar EXPR, which must hold a reference to an unblessed array. The argument will be dereferenced automatically. This aspect of
spliceis considered highly experimental. The exact behaviour may change in a future version of Perl.