The program can be even simpler:
#!/usr/bin/perl use strict; use warnings; my %hash; $hash{$_}=1 for 1 .. 10_000_000; __END__

Your use of a hashref makes it slower because perl has to continuosly dereference it. But there's no need of any particular debugging tool to understand that the problem hast to do with your attempt to fill a hash with a huge number of keys.

The fact is that perl runs quick out of memory and starts swapping to disk. At least this is what I can infer from the music my case just started playing...

The fact that you're filling it an item at a time doesn't help either, but the keys are so many that even preassigning to keys won't help:

#!/usr/bin/perl use strict; use warnings; use constant KEYS => 10_000_000; my %hash; keys %hash=KEYS; $hash{$_}=1 for 1 .. KEYS; __END__

You should really consider a db based approach or a tied hash solution instead.

Also, I'm not really sure, and I may be utterly wrong, but I suspect that due to the nature of the keys, i.e. numbers, they may behave poorly to the hashing function.

Incidentally, were they not that many, I'd initialize it like thus instead:

#!/usr/bin/perl use strict; use warnings; use constant KEYS => 10_000_000; my %hash; keys %hash=KEYS; @hash{1..KEYS}=(1) x KEYS; __END__

(To be sure: this has the same problems as the above!)


In reply to Re: How would you use perl debugging tools to pinpoint the problem here? by blazar
in thread How would you use perl debugging tools to pinpoint the problem here? by tphyahoo

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.