Obviously, if you use longer keys, perl requires more memory to store them. Here's a simple program that creates a hash with given key length and shows how much memory it uses, so you can see how it depends:

use strict; use warnings; use Devel::Size qw(total_size); my $length = $ARGV[0]; my $key = "a" x $length; my %hash; for ( 1 .. 1_000_000 ) { $hash{$key} = 1; $key++; } print "key size: $length\n"; print `ps -p $$ v`; print total_size( \%hash ), "\n"; __END__ key size: 8 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22551 pts/0 S+ 0:01 0 3 146484 128864 3.1 perl hash_k +eys.pl 8 74388680 key size: 16 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22557 pts/0 R+ 0:01 0 3 146484 128860 3.1 perl hash_k +eys.pl 16 82388680 key size: 32 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22563 pts/0 R+ 0:01 0 3 162116 144488 3.5 perl hash_k +eys.pl 32 98388680 key size: 64 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22569 pts/0 S+ 0:01 0 3 193384 175740 4.3 perl hash_k +eys.pl 64 130388680 key size: 128 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22575 pts/0 R+ 0:01 0 3 255936 238240 5.8 perl hash_k +eys.pl 128 194388680 key size: 256 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22581 pts/0 R+ 0:02 0 3 380928 363244 8.9 perl hash_k +eys.pl 256 322388680 key size: 512 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22587 pts/0 S+ 0:04 0 3 630924 613252 15.1 perl hash_k +eys.pl 512 578388680 key size: 1024 PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22597 pts/0 R+ 0:07 0 3 1130868 1113256 27.4 perl hash +_keys.pl 1024 1090388680

In reply to Re: strange keys with a hash by zwon
in thread strange keys with a hash by chuckd

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.