I use "&subset (@array_name, $start-$end)" or "&subset (@array_name, $start, $count)" to pull a continuous subset of an array's items.
# perl0007.lib
# Written: 1999-08-12 James Alarie
# Changed: 2000-07-13 James Alarie
# Use "splice" to vastly improve the speed.
#
# subset(@array, $par1, $par2):
# @array the input array.
# $par1 start subscript, or start-end subscripts.
# $par2 optional count of items to return.
sub subset {
local($ix1, @ix2, $l1, $par1, $par2, @result);
$par2 = pop(@_);
$l1 = index($par2, '-'); # position of dash
if ($l1 > -1) { # a range was given
$par1 = substr($par2, 0, $l1);
$par2 = substr($par2, $l1 + 1);
if ($par2 eq '*') { # to the end
$par2 = $#_;
}
$par2 = $par2 - $par1 + 1;
} else {
$par1 = pop(@_); # start subscript
if ($par2 eq '*') { # to the end
$par2 = $#_ - $par1 + 1;
}
}
if ($par2 == 0) { return @result } # nothing to do
if ($par1 + $par2 > $#_) { # beyond the end
$par2 = $#_ - $par1 + 1; # corrected count
}
@result = splice(@_, $par1, $par2);
return @result;
}
#***** Accessed correctly:
1;