Splice allows you to add, delete elements, or both, at any point in any array
# splice 从列表中切除元素, 列表值会发生改变
# 表示从最后一个元素往回切 6 个元素, 如果超过列表大小,会提示:
# Modification of non-creatable array value attempte
splice(@array, 0, 3) # 切除 0 , 1, 2, 3 四个元素
map say, splice(@array, -6)
To add some elements :
splice(@array, 2) # will remove all the elements from $array[2] to the end of the list
splice (expr, offset, length, list) : removes the elements designated by “offset” and “length” from an array, and replace them with the elements of list
e.g.,
my @array = (0, 1, 2, 3, 4, 5) ;
splice(@array, @array - 3, 1, 6, 7) ; # will remove 3 and push 6, 7 between 2 and 4
splice(@array, $i, 1, $y) # == $array[$i] = $y
“`