Can't you just do:
There will be a very rare (I'd hope) case of a clock tick happening between the call to time and the call to sleep causing one beep to come one second late, but that won't cause the next beep to slip. When a process goes to sleep, you can't guarantee how fast it will be able to wake up anyway (that is the nature of time-share operating systems).$|= 1; my $next= time() + 60; while( 1 ) { print "\a"; sleep $next-time(); $next += 60; }
If that one second turns out to be too much of a problem, then you can use the high-res equivalent:
- tye (but my friends call me "Tye")use Time::HiRes; $|= 1; my( $next, $us )= gettimeofday(); while( 1 ) { print "\a"; $next += 60; usleep tv_interval( [$next,$us], [gettimeofday()] ); }
In reply to (tye)Re: Reasonably accurate timing
by tye
in thread Reasonably accurate timing
by traveler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |