hello every one !
Recently I write a perl script which not long, but it has an array named "@arr_abundant" which contain nearly 30000 elements.
And I make two "for loop" on it on a section
So every time I re run this script, it runs very slowly.

Is there any one can tell me any clues about deal with this problem? such as any cache mechanism. so I can re run it fast for debug?

Really appreciate your help!!

my @arr_abundant; for (12 .. 28123 ){ ### Evaluating [===| ] % done push @arr_abundant, $_ if prob23_type_of_number($_) eq "abundant" + ; } my %hash; # get no repeated abundant number foreach my $i (@arr_abundant){ ### Evaluating [===| ] % done foreach my $j (@arr_abundant) { my $positive = $i + $j; next if $positive > 28123; $hash{$positive} ++; } } # get the sum of positive integers cannot be written as ... my $sum_total; my @arr_sum_two_abundant_numbers=sort {$a <=> $b} keys %hash ; my $n = 1; foreach my $key (@arr_sum_two_abundant_numbers){ for ( my $i=$n ; $i < $key ; $i++) { $sum_total += $i; } $n = $key +1; } print "$sum_total\n";

In reply to Is there any cache mechanism for running perl script by DillonYu

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.