Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Listing Keys in a specific element(s) in an array of hashs

by davidrw (Prior)
on Jun 20, 2005 at 12:15 UTC ( [id://468301]=note: print w/replies, xml ) Need Help??


in reply to Listing Keys in a specific element(s) in an array of hashs

If you want all the unique keys from all the array elements, you can traverse it similar to as described above, and just keep track (in a hash) of the keys you've seen.
my %allKeys; foreach my $i ( 0 .. $#data ){ my $hash = $data[$i]; for (keys %$hash) { push @{$allKeys{$_}}, $i; } } foreach my $key ( sort keys %allKeys ){ my $locations = $allKeys{$key}; printf "Key '%s' was seen %d times at these indices: %s\n", $key, scalar @$locations, join(", ", @$locations); }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-20 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found