my @array = 0 .. 9; my @slice = splice @array, 3, 3; say "@slice"; # prints "3 4 5" say "@array"; # prints "0 1 2 6 7 8 9" say 0 + @array; # prints 7
Splice删除数组元素。
其他答案表明,
splice
),如果您具有要删除的连续元素的上部和下索引,则可以通过n和阵列切片进行操作。 例如:
n
输出为:
use strict; use warnings; my @a=("a".."z"); #We will remove the letters "e" through "u" my $lower=4; my $upper=20; print "$_\n" foreach(@a[grep{$_<$lower or $_>$upper}0..$#a]);