Searching within the hash values of an array of hashes

U

usenet

I have an array of hashes that looks like this:
my @media = (
{
'Name' => 'foo'
'Format' => 'mp3',
},
{
'Name' => 'bar'
'Format' => 'ogg',
},
{
'Name' => 'baz'
'Format' => 'wav',
},
);

I want to know if I have any ogg formatted media. If this was a plain
hash then it would be simple to grep the values. Is there a way I can
do something simple like this on this AoH so I don't have to use a for
loop or something to iterate over the array?

Thanks!
 
X

xhoster

I have an array of hashes that looks like this:
my @media = (
{
'Name' => 'foo'

Missing comma at eol.
'Format' => 'mp3',
},
{
'Name' => 'bar'
'Format' => 'ogg',
},
{
'Name' => 'baz'
'Format' => 'wav',
},
);

I want to know if I have any ogg formatted media.


print "have ogg" if grep $_->{Format} eq 'ogg', @media;

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top