Searching within the hash values of an array of hashes

Discussion in 'Perl Misc' started by usenet@DavidFilmer.com, Aug 26, 2007.

  1. Guest

    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)
     
    , Aug 26, 2007
    #1
    1. Advertising

  2. Guest

    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
     
    , Aug 26, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kazaam
    Replies:
    12
    Views:
    281
    Matthias Wächter
    Sep 13, 2007
  2. Matt Brooks
    Replies:
    16
    Views:
    236
    Matt Brooks
    Sep 16, 2009
  3. Tore Aursand
    Replies:
    3
    Views:
    566
    Anno Siegel
    Sep 16, 2003
  4. Scott  Gilpin
    Replies:
    2
    Views:
    228
  5. Tim O'Donovan

    Hash of hashes, of hashes, of arrays of hashes

    Tim O'Donovan, Oct 27, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    221
Loading...

Share This Page