我从来没有真正学过Perl的任何深度,但我正在通过我的工作做一个课程(我能说"只是为了好玩吗?").我理解基础知识没有任何重大问题,但我现在正在学习参考文献和速记.我对数组的速记和访问引用值有疑问,请考虑下面的两个脚本:
@Codes =
(
["A1W",
["A2Q","A2Z"]],
["B2R","BB3"]
);
$CodeRef = \@Codes;
#full notation
print @{@{@{$CodeRef}[0]}[1]}[1], "\n";
#shorthand notation
print $CodeRef->[0]->[1]->[1], "\n";
Run Code Online (Sandbox Code Playgroud)
my $BookPageArray;
{
$AnotherArray = [24, 18, 36];
$Reference = \$AnotherArray;
$BookPageArray = \$AnotherArray;
$AnotherArray = [53, 256, 42]; count drops to 0
}
undef $Reference;
print ${$BookPageArray}->[0]."\n";
Run Code Online (Sandbox Code Playgroud)我的问题是为什么在第二个例子$BookPageArray
中,最终的print语句中的引用需要在它周围使用大括号,而在第一个示例中,$ CodeRef引用不是?
如果我$
在第二个例子中取出花括号和前面的符号,它告诉我该引用没有数组......
是否与第二个示例使用匿名数据这一事实有关?
perl ×1