Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-25 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found