in reply to sleep?

You can either add a $|++ to unbuffer STDOUT, or you can use the somewhat more Perlish (IMHO)

while (sleep(1)) { print "I'm going back to sleep.\n"; }

Note that this does change the logic slightly, in that the script will sleep for one second before the first print.

Replies are listed 'Best First'.
(Guildenstern) Re: Re: sleep?
by Guildenstern (Deacon) on Mar 20, 2001 at 21:48 UTC
    Then why not say -
    do { print "I'm going to sleep\n"; } while (sleep(1))

    :)

    Guildenstern
    Negaterd character class uber alles!
      Yes, but note that do{}while(); is not actually a loop. You can't use loop control mechanics like last and next. This is noted under Universal Blunders, page 529 in Camel 2:
      • Using loop control statements in do {} while. Although the braces in this control structure look suspiciously like part of a loop BLOCK, they aren't.
      This is also mentioned here.
        Yes, but this is a simple example and does not use any loop control statements. myocom stated in his reply that the while(sleep(1)) construct would sleep first before showing any output - the opposite of what the original author was trying to do in the sample code. In this case, the do {} while () is a perfectly acceptable WTDI.

        Guildenstern
        Negaterd character class uber alles!