Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: hash array question

by Eily (Monsignor)
on Nov 08, 2019 at 16:53 UTC ( [id://11108481]=note: print w/replies, xml ) Need Help??


in reply to hash array question

Where does the first hash come from? Maybe there's a way to get the data directly in the format you want, if the intermediate format (your first one) is useless.

Otherwise something like this might help:

# maybe you can directly iterate on the input, rather than iterate ove +r %first_hash # Get the contained hashes (which are the values of the top hash), bec +ause the keys are not used for my $subhash (values %first_hash) { my $key = $subhash->{LABEL}; # You have the key above, and the associated value is actually $subh +ash ... }

Edit: this is really straightforward, so maybe the information your are missing is how to work with references (a hash within a hash is actually stored through a reference, ie an hashref).

Edit 2: oh ++choroba is right, you can't just have multiple values for the same key. You need an intermediate array. Thanks to the magic of autovivification you can just write: push @{ $hash{$key} }, $value to add a new $value to the array stored at $key (and created it if needed).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-19 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found