Perl, get all hash values
- by Mike
Let's say in Perl I have a list of hash references, and each is required to contain a certain field, let's say foo. I want to create a list that contains all the mappings of foo. If there is a hash that does not contain foo the process should fail.
@hash_list = (
{foo=>1},
{foo=>2}
);
my @list = ();
foreach my $item (@hash_list) {
push(@list,$item->{foo});
}
#list should be (1,2);
Is there a more concise way of doing this in Perl?