Using "Sleep "

Discussion in 'Perl Misc' started by George Kinley, Sep 9, 2004.

  1. for(;;)
    {
    print "a";
    sleep (1);
    }

    The above script does not print any thing on console , till I modify
    it like

    for(;;)
    {
    print "a\n";
    sleep (1);

    }
    why?

    --
    -Gk
    George Kinley, Sep 9, 2004
    #1
    1. Advertising

  2. George Kinley

    Paul Lalli Guest

    "George Kinley" <> wrote in message
    news:vCY%c.24967$...
    > for(;;)
    > {
    > print "a";
    > sleep (1);
    > }
    >
    > The above script does not print any thing on console , till I modify
    > it like
    >
    > for(;;)
    > {
    > print "a\n";
    > sleep (1);
    >
    > }
    > why?


    This is known as output buffering. By default, STDOUT is line-buffered,
    meaning the printed strings get stored until a newline is reached, at
    which point everything is printed. This is controlled by the $|
    variable.

    Read
    perldoc -q buffer
    and
    perldoc perlvar

    to learn more about it.

    Paul Lalli
    Paul Lalli, Sep 9, 2004
    #2
    1. Advertising

  3. George Kinley

    Eric Bohlman Guest

    "George Kinley" <> wrote in
    news:vCY%c.24967$:

    > for(;;)
    > {
    > print "a";
    > sleep (1);
    > }
    >
    > The above script does not print any thing on console , till I modify
    > it like
    >
    > for(;;)
    > {
    > print "a\n";
    > sleep (1);
    >
    > }
    > why?


    Output buffering. perldoc -q flush will give you the detailed answer and
    the appropriate workaround.
    Eric Bohlman, Sep 9, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephen Miller
    Replies:
    3
    Views:
    3,966
    Stephen Miller
    Jul 2, 2004
  2. Lee Garrington

    Trouble using Thread.sleep()......

    Lee Garrington, Oct 1, 2003, in forum: Java
    Replies:
    3
    Views:
    645
    Steve W. Jackson
    Oct 1, 2003
  3. Gonzalo Moreno
    Replies:
    2
    Views:
    12,417
  4. Sam Roberts
    Replies:
    16
    Views:
    376
    Daniel Berger
    Feb 18, 2005
  5. Richard
    Replies:
    7
    Views:
    226
    Richard
    May 22, 2007
Loading...

Share This Page