Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Filter array of hashes for specific keys

by Athanasius (Archbishop)
on Oct 22, 2016 at 03:12 UTC ( [id://1174486]=note: print w/replies, xml ) Need Help??


in reply to Filter array of hashes for specific keys

Hello ddominnik,

Say I have an array of hashes like this:

Actually, what you show is an array of arrays of hashes; the array @response has only one element, an anonymous array containing two hashes. If you really just want an array of hashes (AoH), use parentheses (round brackets) instead of square brackets at the top level:

@response = ( { name => 'foo', id => 'bar', self => 'baz', }, { name => 'foo2', id => 'bar2', self => 'baz2', }, );

See perlreftut and perldsc.

BTW, note that the “fat comma” operator => stringifies its left operand,1 so in this case you don’t have to explicitly quote the key names.

1 “...if it begins with a letter or underscore and is composed only of letters, digits and underscores.” (perlop#Comma-Operator)

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1174486]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-19 23:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found