Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: hash array question

by Eily (Monsignor)
on Nov 08, 2019 at 16:53 UTC ( #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
Node Status?
node history
Node Type: note [id://11108481]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2020-05-26 12:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (150 votes). Check out past polls.

    Notices?