[英]Perl, dereference array of references
In the following Perl code, I would expect to be referencing an array reference inside an array 在下面的Perl代码中,我希望在数组中引用数组引用
#!/usr/bin/perl
use strict;
use warnings;
my @a=([1,2],[3,4]);
my @b = @$a[0];
print $b[0];
However it doesn't seem to work. 但它似乎不起作用。 I would expect it to output 1. 我希望它输出1。
@a
is an array of references @a
是一个引用数组
@b
is $a[1]
dereferenced (I think) @b
是$a[1]
解除引用(我认为)
So what's the problem? 所以有什么问题?
This stuff is tricky. 这个东西很棘手。
@$a[0]
is parsed as (@$a)[0]
, dereferencing the (undefined) scalar $a
@$a[0]
被解析为(@$a)[0]
,解除引用(undefined)标量$a
You wanted to say @{$a[0]}
. 你想说@{$a[0]}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.