How can I tell Perl to run some code every 20 seconds?
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.
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.
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.
for (;;) {
my $start = time;
# your code;
if ((my $remaining = 20 - (time - $start)) > 0) {
sleep $remaining;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With