Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Searching within the hash values of an array of hashes (http://www.velocityreviews.com/forums/t904364-searching-within-the-hash-values-of-an-array-of-hashes.html)

usenet@DavidFilmer.com 08-26-2007 04:18 AM

Searching within the hash values of an array of hashes
 

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)


xhoster@gmail.com 08-26-2007 04:55 AM

Re: Searching within the hash values of an array of hashes
 
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


All times are GMT. The time now is 06:05 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.