in reply to Re: Need sleep walking help
in thread Need sleep walking help

That is it. By adding a \n it will walk. Since \n is not the desired result, is there a way to flush the buffer? (I could not make heads or tails out of the "suffering from buffering" paper, maybe I am too much of a beginner.)

Replies are listed 'Best First'.
Re^3: Need sleep walking help
by Discipulus (Canon) on Feb 01, 2017 at 08:22 UTC
    the answer is already there:

    something change if you put $|++; at the top of your code? I suspect yes.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re^3: Need sleep walking help
by Todd Chester (Scribe) on Feb 01, 2017 at 08:31 UTC
      I don't see the need to use that select calls.

      Infact you are not using STDERR at all and in the case of a use of warn a newline is added anyway. From the docs:

      Prints the value of LIST to STDERR. If the last element of LIST does n +ot end in a newline, it appends the same file/line number text as die + does.

      In case of need of a granular control over buffer behaviour you can use the autoflush method from IO::Handle that is the base class for all other IO handle classes.

      In your example you just need to put $|++; after use strict; use warnings; lines.

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      No, that is not correct.
      STDERR is "unbuffered" by default.
      STDOUT is buffered by default and is the currently selected output file handle by default. You do not need the "select" in this case.

      This should work fine...

      #!/usr/bin/perl use strict; use warnings; $|=1; # turns off stdout buffering mysleep(10); sub mysleep { my $seconds = shift; print "Sleeping for $seconds seconds ... "; for my $second (1..$seconds) { sleep(1); print " $second"; } print " done!\n"; }
      I would not use "Sleep" as the subroutine name. Lower case "sleep" is the library's function name. This kind of upper vs lower case thing can lead to big and confusing troubles! I used "mysleep" instead of "Sleep".

      PS: Something is very odd about your <code>...</code> tags. Do not enclose the <code>...</code> tags inside of something else.

        Where do you get that information?

        $ perl -e "print int STDERR->autoflush for 1..2 " 01 $ perl -e "print int STDOUT->autoflush for 1..2 " 01

        0 means both STDERR and STDOUT were buffered , ie the default is they are buffered