1

Newcomer to Perl so I suspect there is a simple solution to this but I cannot see it despite extensive Googling.

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;
}

The array of allThings being passed in is an array of hashes. I am getting an error on the foreach line telling me that 'Global symbol "%thing" requires explicit package name'.

I know this has something to do with referencing the hash value or key but I am at a loss at the minute. Any help is much appreciated.

1
  • 1
    $thing{special} means the element with key special of hash %thing Commented Feb 13, 2015 at 20:31

1 Answer 1

5

You have an array of hashrefs, not of hashes. You need to use $thing->{special} when when working with hashrefs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.