bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monasterians,
It's easy enough to get the keys in a hash, but what about an array of hashes? All I really need are the keys from just one of the array elements, because the way I'm using the AoH, all the keys are the same in each element of the array.
It would look something like this:
my @AoH = ({'name' => 'Barney', 'age' => '34'},{'name' => 'Fred', 'age +' => '36'},); my %hash = $AoH[0]; print keys %hash; __OUTPUT__ name, age
Of course, that barfs. Is there a way to do this? TIA
—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Extract keys from an Array of Hashes
by BrowserUk (Patriarch) on Dec 16, 2010 at 17:07 UTC | |
by bradcathey (Prior) on Dec 16, 2010 at 17:17 UTC | |
by bradcathey (Prior) on Dec 17, 2010 at 03:23 UTC | |
Re: Extract keys from an Array of Hashes
by toolic (Bishop) on Dec 16, 2010 at 17:17 UTC | |
Re: Extract keys from an Array of Hashes
by eff_i_g (Curate) on Dec 16, 2010 at 18:00 UTC | |
Re: Extract keys from an Array of Hashes
by aartist (Pilgrim) on Dec 16, 2010 at 22:27 UTC |
Back to
Seekers of Perl Wisdom