One minor little 'gotcha' when dealing with cadence -- you actually want the 43200/$n to be the time between successive starts, not between the completion of one and the start of the next (ie, the time to sleep).
To compensate, if we're dealing with something that takes any significant time to run an iteration, we need to track how long each run takes, and subtract that from the time that we're going to sleep:
use IO::Socket; my $sock = new IO::Socket::INET("$remote_server:43") || die $!; my $n = 5; # do this 5 times every 12 hours while (1) # loop forever { my $time = time(); # keep track of when we start print $sock "$data\r\n"; my @output = <$sock>; $output = join('', @output); if ($output =~ /$no_match/gi) { &true; } else { &false; } # sleep for the PERIOD, minus the DURATION sleep( int(43200 / $n) - ( time() - $time) ); }
In reply to Re^2: loop control
by jhourcle
in thread loop control
by webshark
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |