Searching within the hash values of an array of hashes

Searching within the hash values of an array of hashes

am 26.08.2007 06:18:20 von 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!

--
David Filmer (http://DavidFilmer.com)

Re: Searching within the hash values of an array of hashes

am 26.08.2007 06:55:21 von xhoster

usenet@DavidFilmer.com wrote:
> 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

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB