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