Rabotnik has asked for the wisdom of the Perl Monks concerning the following question:

Howdy folks! I read that if u set OUTPUT_AUTOFLUSH to non zero, then auto(buffer)flushing is applied for the "currently selected channel". What is the currently selected channel? The last HANDLE used in print? e.g.
print "asd"; $OUTPUT_AUTOFLUSH=1; #this sets the flushing
Does this cause autoflushing for STDOUT? Until what (i guess until another HANDLE is used, e.g.: print STDERR "asd";)?

Replies are listed 'Best First'.
Re: OUTPUT_AUTOFLUSH
by Juerd (Abbot) on Jun 06, 2002 at 14:20 UTC

    It works on the currently selected handle. By the way, you have to use English to use $OUTPUT_AUTOFLUSH. It's easier to use $| (perlvar) instead.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

Re: OUTPUT_AUTOFLUSH
by Beatnik (Parson) on Jun 06, 2002 at 14:19 UTC
    You do need English for it, IIRC...
    It works until you unset that filehandle. You can select another filehandle too ofcourse :)

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: OUTPUT_AUTOFLUSH
by Aristotle (Chancellor) on Jun 06, 2002 at 14:51 UTC
    By default it works on STDOUT. (As has been said, select() another filehandle to change the autoflushing on it.) Note that unlike your example, you should use it prior to performing any operations on that filehandle:
    $|++; print "asd";
    As, again, has been said, the variable is really called $|, and the long name is only available if you use English;. You can also use IO::Handle; and then say STDOUT->autoflush(1);.

    Makeshifts last the longest.

Re: OUTPUT_AUTOFLUSH
by Rabotnik (Initiate) on Jun 11, 2002 at 12:43 UTC
    Hi! I fixed my problem... I put $|++ right @ the start of the script. At first i tried using the same cmd, but somewhere deep in the script (before the 1st print). 10x