M
mrstevegross
I have a list of hashes that looks like this:
my @list = (
{ Name => 'Foo', X => Y },
{ Name => 'Bar', X => Y },
{ Name => 'Baz', X => Y },
);
I would like to iterate across the list-of-hashes and extract just the
values of the 'Name' key as a list. I had hoped that the following
code would do the trick:
my @names = grep { $_->{Name} } @list;
But it doesn't, because the grep simply matches the hash reference but
doesn't return the value of the named attribute. Is there a quick way
to make this work, other than iterating across the list with a
foreach() statement?
Thanks,
--Steve
my @list = (
{ Name => 'Foo', X => Y },
{ Name => 'Bar', X => Y },
{ Name => 'Baz', X => Y },
);
I would like to iterate across the list-of-hashes and extract just the
values of the 'Name' key as a list. I had hoped that the following
code would do the trick:
my @names = grep { $_->{Name} } @list;
But it doesn't, because the grep simply matches the hash reference but
doesn't return the value of the named attribute. Is there a quick way
to make this work, other than iterating across the list with a
foreach() statement?
Thanks,
--Steve