Splice: is it ok when the end of LENGTH passed the array?

splice

OFFSETIs everything all right when it is inside the array, but the end LENGTHgoes past the end of the array?

+3
source share
2 answers

Easy to try.

$ 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.

I am sure that this will not change.

+2
source

Seems right. Doc talks about this scenario. The code below illustrates that the length abroad is valid.

@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 ;
+1
source

All Articles