sschneid has asked for the wisdom of the Perl Monks concerning the following question:

Is there a 'quick & easy' way to count the number of keys in a hash without creating an (incremental) variable and mapping through it?

-s.

Replies are listed 'Best First'.
Re: Counting number of keys in a hash.
by gaal (Parson) on Jul 27, 2004 at 19:36 UTC
    my $count = keys %hash;
Re: Counting number of keys in a hash.
by sweetblood (Prior) on Jul 27, 2004 at 19:37 UTC
    try $hash_cnt = scalar keys %hash

    HTH

    Sweetblood

      Thanx from me too. I just had to do this today actually. I figured there was a better way than my quick solution of:

      my $counter = 0; $counter++ for keys %hash;

      --
      "A long habit of not thinking a thing wrong, gives it a superficial appearance of being right." -- Thomas Paine
      naChoZ

A reply falls below the community's threshold of quality. You may see it by logging in.