in reply to cron-like timing within perl script?

You're very close to the right answer, and if I take your code, it would look like this:
while (1) { next_time=time+60; get_data_taking_55_seconds_give_or_take_a_few; sleep next_time-time; write_log_file; }

Note that you will still have a +/- 1 second drift, so the exact time of measurements would still drift.

For higher accuracy, you pre-determine the times:

next_time=time; while (1) { next_time=next_time+60; get_data_taking_55_seconds_give_or_take_a_few; sleep next_time-time; write_log_file; }

Replies are listed 'Best First'.
Re: Re: cron-like timing within perl script?
by Anonymous Monk on Feb 28, 2004 at 20:06 UTC
    This looks like the ticket... particularly if I use Time::HiRes to get subsecond time and sleep resolutions; that'll let me stay within my measurement tolerances.

    Thanks! This is a great resource!!!

    John

      You don't need Time::HiRes if you always sleep to a multiple of the 1-second system clock, which sleep(2) does. Since your requirement was an integer multiple of 1 second, that's the simplest. Now, if you wanted a task performed every 59.23 seconds, yes, Time::HiRes would help.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

      Sorry... didn't realize I wasn't logged in when I left that. Thanks again!

      John