Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hash of Hashes - Keys Count 1

Status
Not open for further replies.

Extension

Programmer
Nov 3, 2004
311
CA
Hi,

I have a hash of hashes and I would like to know how to do a quick count of the hash keys for the "second level".

For a simple hash, I'm doing this:
Code:
$KeysCount = keys %Hash;

But for a hash of hashes, if I do the same I will get a record count only for the "first level" of keys.

I woud like to avoid looping through the hash to get the record count.
 
to avoid looping you need to know the name(s) of the hash keys:

Code:
$n = keys %{ $Hash{key_name} };

otherwise you will have to loop through the first level hash:

Code:
my $n = 0;
foreach my $key (keys %Hash) {
   $n += keys %{$key}
}

- Kevin, perl coder unexceptional!
 

Thanks KevinADC. I guess I will have to loop through all the Hash keys.

Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top