Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Answer: What is the best way to run periodic tasks (once per minute)?

( #24485=categorized answer: print w/ replies, xml ) Need Help??

Q&A > programs and processes > What is the best way to run periodic tasks (once per minute)? contributed by qi3ber

Corion is correct. A modification that I have had to make on several occasions allows for more time intensive tasks is this:

while (1) { $waketime = time + $sleep_duration; &do_complex_things; sleep($waketime-time); }


Something else that you might want to look into is the Time::HiRes module.

Comment on Answer: What is the best way to run periodic tasks (once per minute)?
Download Code
Re: Answer: What is the best way to run periodic tasks (once per minute)?
by flyingmoose (Priest) on Feb 03, 2004 at 00:25 UTC
    A more Unix-y way to do this would be to use the alarm function. See 'perldoc -f alarm' for details.
    #!/usr/bin/perl use strict; my $interval = 60; # seconds between calls + # sub will be called every $interval seconds my $process = sub { print "processing!\n" }; + # engage the alarm system $SIG{ALRM} = sub { &$process; alarm $interval; }; + alarm $interval; + # function will be called every 60 seconds for rest of program...

    Another alternative would be to upgrade the program to use POE events. This would be the route I would take. The alarm demo is more for historical interest and fiddling than for anything else.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2015-07-06 11:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (72 votes), past polls