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

jaa has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I have a Hash-of-hash, and each of the child-hashes contains a value that I am interested in accessing just once. This value is the same for all of the child hashes.

I have found two ways to access the value, but wonder if there is a better way??

my $hoh = { apples => { source => 'uk', colour => 'red', }, pears => { source => 'uk', colour => 'green', }, bananas => { source => 'uk', colour => 'yellow', }, }; # naff: get source, using var in a list assignment my ( $any ) = values %$hoh; print "source: ", $any->{source}, "\n"; # naff: create an anonymouse array and access element[0] print "source: ", ${[values %$hoh]}[0]{source}, "\n";

Regards,

Jeff