in reply to system-clock-safe timers without time()?

This looks like a job for POSIX::times() - among other things, this call gives you the number of clock ticks since some time that is guaranteed to change only on system reboot. (Usually, this is the number of clock ticks since system reboot, but in theory it could use some different base time)

This allows you to write something like this:

use POSIX; sub mytime { my ($clock_ticks) = POSIX::sysconf(&POSIX::_SC_CLK_TCK); return ((POSIX::times())[0] / $clock_ticks); }

which gives you the number of seconds since that base time. Rewriting it so that POSIX::sysconf is called only once is left as an exercise for the reader.

Replies are listed 'Best First'.
Re: Re: system-clock-safe timers without time()?
by edan (Curate) on Apr 15, 2003 at 11:10 UTC

    fizbin++

    Great stuff - just what I was looking for - didn't know it existed until now - nice to have in my Bag O' Tricks.

    Thanks a bunch!!

    --
    3dan