I expect the reason it give you no problems the second way is that you're only running it once, sleeping for 10 seconds, and exiting (you exit the loop on the first time through).

I think you and PrakashK are both under a slightly misapprehension as to what do does: it "does" the code in a file you specify, but it does it within the name space of the currently running script (and it does the same thing every time you do it). This is very useful for importing configuration variables, but not very useful for avoiding memory leaks.

I suspect, therefore, that if you try substituting system for do, it will solve that problem, giving you an acceptable work-around for running the script repeatedly.

It will not solve your overall problem, however: most likely that is caused by the use of global variables in a non-scalable manner, as indicated by synapse0 and PrakashK. This can be solved by making your variables lexically scoped, using my (this makes it sound slightly simpler than it is). I'd explain why this is, but Dominus explains it so much better in Coping with Scoping (TPJ) that I'll just recommend that you read that instead. :-)

If you're modifying globals in your subroutines (which it seems very likely you are), don't do that! :-) Instead, pass values to them explicitly, and give them useful return values. If you write subs this way, casual readers like us (and you, two months from now) will be able to figure out which variables they modify, and mysterious bugs will be less likely to happen.

I strongly suggest using use strict; at the top of every large script you write (and the small ones too, just to keep in practice). Again, I'd explain exactly why (it has to do with those lexically scoped variables), but tachyon wrote a node precisely to avoid that duplication of effort, so I'll just point you to it: Use strict warnings and diagnostics or die. (Though if you're new to Perl I should perhaps note that he doesn't mean that last part entirely literally...)

Sorry for the somewhat scattershot nature of this reply--sometimes that's all my brain will produce.



If God had meant us to fly, he would *never* have give us the railroads.
    --Michael Flanders


In reply to Re^3: Buffer overflow by ChemBoy
in thread Buffer overflow by mikeo

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.