For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2008 > Re: Return number of keys in a hash of hash? Looping through "sub hash"?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Return number of keys in a hash of hash? Looping through "sub hash"?
Tom Phoenix

2008-01-24, 7:07 pm

On Jan 24, 2008 9:07 AM, <pzimmermann@gmail.com> wrote:

> I'd like to get the number of keys in hash of hashes. I know that I
> can do something like $count = keys( %myHash ), but how would I go
> about finding the number of keys in a sub-hash?


my $count = keys %{ $sub_hash_reference };

You can replace $sub_hash_reference with any expression that returns
the reference to your sub-hash, such as $myHash{fred}, say.

> Alternately, how could I loop through keys in a hash of a hash?


foreach my $key (keys %{ $sub_hash_reference }) { ... }

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com