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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

number of keys in a hash

Status
Not open for further replies.

EfratS

MIS
Joined
Aug 4, 2004
Messages
15
Location
CA
Hi,
how can I know the number of keys I have in a hash?

Thanks.
 
Code:
%hash = (1 =>1, 2 => 2, 3 => 3);

@keys = keys(%hash);
$numkeys = @keys;

print $numkeys;

There will be better ways I'm sure, but you will end up with an array of the keys too in @keys
 
Or you can just do:

Code:
$numkeys = keys(%hash);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top