我在 perl 中有一个数组,其中包含排序的非连续值。例如:1 2 3 5 7 11 13 15。
我想删除所有在 and 之外的值,lower并在返回的选择中upper保留lowerand 。upper我这样做的方法看起来像这样(可能可以通过使用来改进slice):
my @culledArray;
for ( my $i = 0; $i < scalar(@array); $i++ ) {
if ( ( $array[$i] <= $_[1] ) and ( $array[$i] >= $_[0] ) ) {
push(@culledArray, $array[$i]);
}
}
其中lower和upper分别包含在$_[0]和$_[1]中。有没有内置的 perl 可以做到这一点?