I have a set of Perl programs that run in a controlled infinite loop. They are all supposed to work n times per minute and sleep inbetween. Furthermore, they are supposed to work at given moments in the minute, like for instance every time the seconds show 15 or 45.

As a way to control when these programs should execute or not, I use the CPAN module Schedule::ByClock, which will let me configure at what seconds in the minute the program should wake up and do things.

The Schedule::ByClock is a wrapper around sleep() which hides the somewhat bizarre calculation to find out how many seconds there are until the next time the seconds on the clock are for instance 12. Tricky if the seconds right now are at 57, since 12 - 57 != 15 and 15 is indeed the number of seconds to sleep() to reach the moment when the seconds are 12. (It's even tricky to explain in a clear way. ;-)

The module can also wait until given minutes within the hour, but I've never had reason to use that feature.


Everything went worng, just as foreseen.


In reply to Re: infinite loops == bad? by Biker
in thread infinite loops == bad? by BUU

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.