in reply to infinite loops == bad?
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.