I am currently writing a script that runs continually, but only actually does something every two minutes. I had previously achieved this by doing this:
while()
{
...code...
sleep(120);
}
However, the sleep function has become a terrible labryinth of problems to my script and I would like to find a more efficient way to run my script continually than with a while loop and a sleep function. Any suggestions? Oh and this is on a Win32 platform.
This is what the script does essentially. It automates an rsync backup of files betwen two servers every two minutes. The problem I was having with sleep is that it delays any print/output file statements until after the sleep has executed, and this often resulted in output files getting truncated.
for example if i did this:
print "hello";
sleep(120);
The script would wait two minutes before printing out hello. Very strange problem and i don't know how to fix it, maybe you guys do?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.