I'm kind of new To Perl so bare with my idiocy and the simplicity of this script. The script tests number successivly to be prime or not. I will include the script bellow. Everytime I re-define a variable it seems to use a new chunk of memory. Is there a way I can prevent this for both $Divider and $Number. Or at least make it release the previously used memory. The script run for about 3 minutes then it starts using swap space Here It Is
#open(LOUTPUT,"lastoutput") or die "Unable To Open lastoutput File. #Please Ensure That This File Exists And Contains On One Line. This Fi +le #Must Only Contain Numbers"; #$number=<LOUTPUT>; $number=3; #close(LOUTPUT); $divisor = 2; test(); sub test() { # Un-Comment The Next Line For More Output #print("NUM=$number DIV=$divisor\n"); if ($number / $divisor == int($number / $divisor)) { # Number Is Prime if ($number == $divisor) { print("Prime $number\n"); # open(OUTPUT,">>output"); # print(OUTPUT "$number\n"); # close(OUTPUT); } # Number Is Not Prime $divisor = 2; $number = $number + 1; } $divisor = $divisor + 1; #sleep(1); test(); } # open(LOUTPUT,">lastoutput"); # print(LOUTPUT "$number"); # close(LOUTPUT);
Sorry its got lots of comments but it can do more than I want it to do for testing any help is greatly apreciated.


In reply to Perl Not Releasing Memory by rekcah

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.