【发布时间】:2013-02-06 07:51:37
【问题描述】:
有谁知道如何取消引用散列的散列,以便我可以在我的子例程中使用它。如您所见,我无法在我的子例程中访问我的 Hash of Hashes 数据结构。
my $HoH_ref = \%HoH; # reference the hash of hashes
for(@sorted) {
print join("\t", $_, get_num($_, $HoH_ref))
}
sub get_num {
my ($foo) = shift;
my $HoH_ref = shift;
my %HoH = %{$HoH_ref}; # dereference the hash of hashes
my $variable = %HoH{$foo}{'name'};
# do stuff
return;
}
我在%HoH{ 附近的倒数第二行%HoH{$protein}{'degree'} 上遇到语法错误,并且哈希的哈希无法识别来自%HoH 的$protein 键。我收到错误消息:Global symbol "$protein" requires explicit package name。谢谢
【问题讨论】:
-
如果不看整个脚本就很难判断,但我认为你想要
$HoH{$foo}{'name'}而不是%HoH{$foo}{'name'}。 -
啊好吧,就是这样。谢谢
标签: perl reference subroutine dereference hash-of-hashes