... since the leading number is exactly what you want, the numification is actually successful ...
However, the leading number may not be quite what is wanted.

Consider the following example:

>perl -wMstrict -le "my %hash = ( one => { fee => 33, fie => 44, }, two => { foo => 2, bar => 3, baz => 4, }, ); my $k_n = keys %{ $hash{one} }; my $k_s = '' . %{ $hash{one} }; print $k_n; print $k_s, ' <--'; print scalar keys %{ $hash{two} }; print '' . %{ $hash{two} }; " 2 1/8 <-- 3 3/8 >perl -wMstrict -le "my %hash = ( one => { fee => 33, xyz => 44, }, two => { foo => 2, bar => 3, baz => 4, }, ); my $k_n = keys %{ $hash{one} }; my $k_s = '' . %{ $hash{one} }; print $k_n; print $k_s, ' <--'; print scalar keys %{ $hash{two} }; print '' . %{ $hash{two} }; " 2 2/8 <-- 3 3/8
In the both cases, the evaluation of  scalar keys %{ $hash{one} } (or of  keys %{ $hash{one} in a scalar context) is (and always will be) the same: 2.

However, the first digit of the stringization of  '' . %{ $hash{one} } is not the same in both cases. There has been an unfortunate collision in  one => { fee => 33, fie => 44 } and both 'fee' and 'fie' occupy the same bucket of the 8 allocated for this (anonymous) (sub-)hash. With  one => { fee => 33, xyz => 44 }, this tragedy has been avoided and the two keys occupy two separate buckets.

Moral: As recommended by kennethk, always use the scalar evaluation of keys, not the stringization of the hash which, while interesting, may be misleading. And please don't suppress warnings without good reason.

Update: Here's a much more concise example. The details of the discussion above don't quite apply any more, but you get the picture.

>perl -wMstrict -le "my %ha = ( fee => 33, fie => 44, ); my %hb = ( fee => 33, xyz => 44, ); printf qq{keys (%s): %ld %s \n}, join(' ', sort keys %$_), scalar keys %$_, 'buckets used/allocated: ' . %$_, for \(%ha, %hb); " keys (fee fie): 2 buckets used/allocated: 1/8 keys (fee xyz): 2 buckets used/allocated: 2/8

In reply to Re^2: num keys of the hash within hash? by AnomalousMonk
in thread num keys of the hash within hash? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.