in reply to Reasonably accurate timing

Can't you just do:

$|= 1; my $next= time() + 60; while( 1 ) { print "\a"; sleep $next-time(); $next += 60; }
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).

If that one second turns out to be too much of a problem, then you can use the high-res equivalent:

use Time::HiRes; $|= 1; my( $next, $us )= gettimeofday(); while( 1 ) { print "\a"; $next += 60; usleep tv_interval( [$next,$us], [gettimeofday()] ); }

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: Reasonably accurate timing
by traveler (Parson) on Jul 24, 2001 at 18:05 UTC
    Thanks. I used effectively the Time::HiRes version, but with sleep and time as they give good fractional values.