I have problems following, and it really depends what the OP really wants (this has a strong stench of an XY problem)

For one possible interpretation:

use Time::HiRes (sleep time); my $next_time = time(); while (1) { next if time() < $next_time; $next_time += 60; # no accumulated lag my $price = fetch(); do_it($price); my $took = time()- ($next_time-60); handle_edge_case() if $took > 60; sleep 59 - $took; }

(totally untested, there are most probably dragons...)

The idea is that you only skip at max 59 seconds (or even a bit more) with sleep to let the loop catch the "exact time".

It still needs to handle the edge-case that fetch() and do_it() $took longer than 60 secs tho.

But how exactly really depends on the problem to solve...

So what am I missing justifying two communicating processes???

edit

The logic might be clearer if I calculated $remain = $next_time - time(); instead of $took ... left as task for the interested reader :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re^5: making a loop script with a remote URL call faster by LanX
in thread making a loop script with a remote URL call faster by brandonm78

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.