Perl中,引用解引用数组 [英] Perl, dereference array of references
本文介绍了Perl中,引用解引用数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的Perl code,我希望被引用数组内的数组引用
In the following Perl code, I would expect to be referencing an array reference inside an array
#!/usr/bin/perl
use strict;
use warnings;
my @a=([1,2],[3,4]);
my @b = @$a[0];
print $b[0];
但它似乎并没有工作。我期望它输出1。
However it doesn't seem to work. I would expect it to output 1.
@a
是引用数组
@b
是 $ A [1]
解除引用(我认为)
@b
is $a[1]
dereferenced (I think)
那么,有什么问题呢?
推荐答案
这东西是棘手的。
@ $ A [0]
被解析为(@ $一)[0]
,取消引用(未定义)标 $ A
@$a[0]
is parsed as (@$a)[0]
, dereferencing the (undefined) scalar $a
您想说的话 @ {$ a [0]}
。
这篇关于Perl中,引用解引用数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文