in reply to Re: Count of HoA elements
in thread Count of HoA elements

This is wrong. There is absolutely no reason to iterate the hash to count the elements!

c:\test>p1 Perl> %a = 'a' ..'z';; Perl> print scalar values %a;; 13 [0] Perl> print scalar keys %a;; 13

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^3: Count of HoA elements
by ikegami (Patriarch) on Jan 19, 2007 at 20:31 UTC

    He asked for the number of elements in the HoA. I took that to mean 5 for the following structure:

    my %h = ( k1 => [ qw( a b c ) ], k2 => [ qw( d e ) ], );

    Your solution simply returns the number of elements in a hash. It could be that's what he meant, but that's now how I interpreted his question.

    This is wrong.

    Not so hasty on the wrong. Fletch and Jenda also interpreted the question like I did.