我有一个对数组的引用$arr_ref
。我想获得对仅包含i..j
原始数组中单元格的数组的引用。
问问题
154 次
3 回答
7
@slice = @{$arr_ref}[$i..$j];
于 2010-09-14T12:40:47.970 回答
5
my $r = [0..9];
print $_, "\n" for @$r[3..5];
如果包含引用的变量比普通标量更复杂,请将其括在大括号中。这是必需的,因为取消引用发生在下标查找之前:
my @refs = ( [0..9], [100..109] );
print $_, "\n" for @{ $refs[1] }[4..8];
于 2010-09-14T12:35:49.887 回答
4
@rainbow = ("red", "green", "blue", "yellow", "orange", "violet", "indigo");
$arr_ref = \@rainbow;
$i = 1;
$j = 3;
@slice = @$arr_ref[$i..$j]; # @slice is now green blue yellow
于 2010-09-14T12:36:58.480 回答