Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by Fang (Pilgrim)
on Jun 20, 2005 at 12:06 UTC ( [id://468296]=note: print w/replies, xml ) Need Help??


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

I guess you want to traverse the array, and then traverse each hash elements. One solution could be:

for my $hash (@data) { for (keys %$hash) { ... }

If you simply want to list the keys of a hash, you can do:

my @keys = keys %{$data[0]}; # or [1], or [2], ...

Hope this helps.

Replies are listed 'Best First'.
Re^2: Listing Keys in a specific element(s) in an array of hashs
by Smylers (Pilgrim) on Jun 20, 2005 at 14:19 UTC
    I guess you want to traverse the array, and then traverse each hash elements.

    Depending on what the data's being used for, for quickly printing any complex data structure you can often avoid writing any loops yourself just by using YAML (or Data::Dumper if you prefer):

    use YAML qw<Dump>; print Dump \@data;

    Smylers

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-20 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found