splice:当LENGTH的结尾超过数组时,它可以吗?

时间:2012-05-11 08:24:50

标签: perl splice

splice

是否可以,当OFFSET在数组中但LENGTH的结尾超过数组末尾时?

2 个答案:

答案 0 :(得分:2)

易于尝试。

$ perl -wE'
   my @a = "a".."e";
   my @b = splice @a, 2, 10;
   say 0+@b, " elements were removed.";
   say 0+@a, " elements remain."
'
3 elements were removed.
2 elements remain.

我完全相信这不会改变。

答案 1 :(得分:1)

似乎有效。该文件说明了这种情况。以下代码说明了超出边界的长度是有效的。

@array = ('this','is','for','testing','this','is','for','testing');
@array1 = (1,2,3,4,5,6,7,8,9,10);


splice @array,5,100,@array1;

print join "\n", @array ;