作者:VW旻shi只吃货8453 | 来源:互联网 | 2023-09-23 15:46
ThismaybeasillyquestionThefollowingcodeoutputsthecontentsof@arrayrefand@arraycont
This may be a silly question... The following code outputs the contents of @arrayref
and @arraycont
respectively. Note the difference between them and the way the values of them are assigned. I know what the anonymous array does, but can anybody explain why there is a difference?
这可能是一个愚蠢的问题......以下代码分别输出@arrayref和@arraycont的内容。请注意它们之间的差异以及它们的值的分配方式。我知道匿名数组的作用,但有人可以解释为什么会有区别吗?
Thank you very much.
非常感谢你。
@arrayref = ();
@array = qw(1 2 3 4);
$arrayref[0] = \@array;
@array = qw(5 6 7 8);
$arrayref[1] = \@array;
print join "\t", @{$arrayref[0]}, "\n";
print join "\t", @{$arrayref[1]}, "\n";
@arraycOnt= ();
@array = qw(1 2 3 4);
$arraycont[0] = [@array];
@array = qw(5 6 7 8);
$arraycont[1] = [@array];
print join "\t", @{$arraycont[0]}, "\n";
print join "\t", @{$arraycont[1]}, "\n";
outputs
输出
5 6 7 8
5 6 7 8
1 2 3 4
5 6 7 8
3 个解决方案