in reply to Re: hash count
in thread hash count

I usually use "scalar keys %hash" to find how many pairs are in a %hash.

scalar grep defined($_) values %hash

I think that should be:

scalar grep defined, values %hash;

or

scalar grep { defined } values %hash;

Replies are listed 'Best First'.
Re^3: hash count
by AnomalousMonk (Archbishop) on Mar 25, 2009 at 15:22 UTC
        scalar grep defined($_) values %hashI think that should be: ...
    It could be as you have written it, but I think moritz may have been considering the relative inexperience of the OPer by passing the parameter explicitly rather than implicitly.

    Also, the code fragment was
        scalar grep defined($_), values %hash
    (comma present after the defined($_) built-in call) in moritz's original reply (unless moritz has been updating replies without noting the fact – unlikely!).

      (unless moritz has been updating replies without noting the fact – unlikely!).

      I did, mea culpa.

      (I sometimes do that when the node is still very new and there are no replies and it's a small change. But if it causes confusion, I try to clarify it).

Re^3: hash count
by moritz (Cardinal) on Mar 25, 2009 at 15:15 UTC
    Yes, I forgot the comma after the defined, and updated my post. Thanks to ikegami for noting it.