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;
}
Run Code Online (Sandbox Code Playgroud)
传入的allThings数组是一个哈希数组.我在foreach行上收到一个错误,告诉我'全局符号'%"需要显式包名".
我知道这与引用哈希值或键有关,但我现在处于亏损状态.任何帮助深表感谢.