You are missing the conceptual loophole here.

> print something();

So what if something() takes longer than a second?

Your sleep would just skip the missed steps till the following interval.

The clean approach would be to include an exception handling.

Apart from this could the OS be too busy to return in time, that's why sleep only guaranties minimal time.

See Re: missing second of time

> I wonder if the perldoc for sleep should add ...

All these conditions might not be true in your case, but how do you want to include the general case in the docs???

I think this use cases are best covered in a dedicated module.

Update

Might be interesting to compare how setInterval() in JS is handling those cases.

Update

From what I read after searching JS setInterval long running function it seems that delayed calls are queued to be executed later, and this without raising an exception. ... Ugly.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice


In reply to Re^3: missing second of time by LanX
in thread missing second of time by Anonymous Monk

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.