Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

The "2/8" of a hash in scalar context is just a representation of the number of "buckets" used/assigned for the hash. Note that more than one key can be assigned to the same "bucket" depending on how the hashing algorith works on the keys involved and that keys can be redistributed when more "buckets" are assigned as the hash grows.

$ perl -Mstrict -Mwarnings -E ' > my %hash; > say scalar %hash; > for ( q{a} .. q{z} ) > { > $hash{ $_ } = 1; > say qq{$_ - @{ [ scalar %hash ] }}; > }' 0 a - 1/8 b - 2/8 c - 3/8 d - 4/8 e - 5/8 f - 6/8 g - 6/8 h - 7/16 i - 8/16 j - 9/16 k - 9/16 l - 10/16 m - 10/16 n - 11/16 o - 11/16 p - 14/32 q - 14/32 r - 14/32 s - 15/32 t - 15/32 u - 16/32 v - 16/32 w - 17/32 x - 17/32 y - 18/32 z - 19/32 $

I hope this is helpful.

Cheers,

JohnGG


In reply to Re^3: Hash of hashes assignment by johngg
in thread Hash of hashes assignment 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-19 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found