Perl - 迭代一系列哈希问题

时间:2015-02-13 18:04:17

标签: arrays perl hash

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行上收到错误,告诉我'全局符号'%“需要显式包名称。”

我知道这与引用哈希值或键有关,但我现在处于亏损状态。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:5)

你有一个 hashrefs 的数组,而不是哈希。在使用hashrefs时需要使用$thing->{special}

相关问题