Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell Perl to run some code every 20 seconds?

Tags:

perl

How can I tell Perl to run some code every 20 seconds?

like image 698
aks Avatar asked Sep 20 '10 07:09

aks


People also ask

What is the difference between for loop and for each loop in Perl?

There is no difference. From perldoc perlsyn: The foreach keyword is actually a synonym for the for keyword, so you can use foreach for readability or for for brevity.

Do while loop in Perl?

while loop example. In practice, you use the do... while loop statement when you want the loop executes at least one before the condition is checked. When you enter the by string in the command line, the condition in the do while statement becomes false that terminates the loop.

How do I add a pause in Perl script?

Perl | sleep() Function sleep() function in Perl is an inbuilt function which is used to delay the execution of the current script for a specified number of seconds or forever if parameter is not specified. The sleep( ) function accepts seconds as a parameter and returns the same on success.


1 Answers

for (;;) {
    my $start = time;
    # your code;
    if ((my $remaining = 20 - (time - $start)) > 0) {
        sleep $remaining;
    }
}
like image 135
Eugene Yarmash Avatar answered Nov 01 '22 06:11

Eugene Yarmash