Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: extracting elements by key from an array of hashes

by ciderpunx (Vicar)
on Sep 25, 2015 at 10:06 UTC ( #1143002=note: print w/replies, xml ) Need Help??


in reply to Re: extracting elements by key from an array of hashes
in thread extracting elements by key from an array of hashes

True that. However, the data is coming from an xmlrpc source via XML::RPC and that's how it's structured. I don't have control over the source API or at least I don't want to change it.

  • Comment on Re^2: extracting elements by key from an array of hashes

Replies are listed 'Best First'.
Re^3: extracting elements by key from an array of hashes
by choroba (Archbishop) on Sep 25, 2015 at 10:35 UTC
    You can easily create a temporary hash to do the searches:
    my %hash = map %$_, @rpc;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^3: extracting elements by key from an array of hashes
by davido (Cardinal) on Sep 25, 2015 at 14:57 UTC

    Keep in mind that you have no obligation to store data internally in inconvenient formats. If it is more convenient to manipulate it internally as a hash, do that conversion at the earliest possible point after reading it in, and convert back at the latest possible point if you ever have to output the structure again.


    Dave

Re^3: extracting elements by key from an array of hashes
by Anonymous Monk on Sep 25, 2015 at 10:45 UTC
    ... and if there is potentially more than one value per bucket, simply make each element an arrayref. Auto-vivification makes this trivially easy to do.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2020-09-24 09:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I don’t succeed, I …










    Results (132 votes). Check out past polls.

    Notices?