http://www.perlmonks.org?node_id=11108481


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).