【发布时间】:2015-02-13 18:04:16
【问题描述】:
Perl 的新手,所以我怀疑有一个简单的解决方案,但尽管进行了大量的谷歌搜索,但我看不到它。
my @special_things = get_special_things(\@allThings);
sub get_special_things {
my $things = shift;
my @specialThings;
foreach my $thing (@$things) {
if ($thing{special} == 1) {
push(@specialThings, $things);
}
}
return @specialThings;
}
传入的 allThings 数组是一个哈希数组。我在 foreach 行上收到错误消息,告诉我“全局符号“%thing”需要显式包名”。
我知道这与引用哈希值或键有关,但我现在不知所措。非常感谢任何帮助。
【问题讨论】:
-
$thing{special}表示哈希%thing的键为special的元素