From: Ben Morrow on

Quoth "Uri Guttman" <uri(a)StemSystems.com>:
> >>>>> "JE" == J�rgen Exner <jurgenex(a)hotmail.com> writes:
>
> JE> "efoss(a)fhcrc.org" <efoss(a)fhcrc.org> wrote:
> >> I want to be certain that a print statement is immediately executed.
> >> Googling around led me to use "$| = 1". Is this correct? Here is an
> >> example of how I'm using it:
> >>
> >> $| = 1;
> >> $test = 3;
> >> print "test is $test\n";
>
> JE> Yes, that is the correct use of $|.
>
> actually that never uses $| ! the print string ends in newline so it
> will always be flushed to stdout. $| is meant for when you print text
> without a newline (say a prompt or partial output or to a socket).

Huh? That's only if the filehandle is line-buffered; AFAIK PerlIO only
supports line-buffering for direct output to a tty.

Ben

From: efoss on
Thanks all.

Eric
From: Uri Guttman on
>>>>> "W" == Willem <willem(a)snail.stack.nl> writes:

W> Uri Guttman wrote:
W> ) actually that never uses $| ! the print string ends in newline so it
W> ) will always be flushed to stdout. $| is meant for when you print text
W> ) without a newline (say a prompt or partial output or to a socket).
W> )
W> ) also since the program ends there, you also won't see any difference
W> ) with setting $| or not as stdout gets flushed then as well. you need to
W> ) print a string without a newline and then sleep or wait for input or
W> ) something to see the difference.

W> AFAIK, not true if stdout is redirected to a file.

then the original question is moot. obviously he is asking about stdout
to a terminal where this matters (or a socket which i covered). and for
sockets, the correct call is syswrite anyhow. you can even use it for
stdout and bypass all buffering and not need to deal with $|.

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Uri Guttman on
>>>>> "BM" == Ben Morrow <ben(a)morrow.me.uk> writes:

BM> Quoth "Uri Guttman" <uri(a)StemSystems.com>:
>> >>>>> "JE" == J�rgen Exner <jurgenex(a)hotmail.com> writes:
>>
JE> "efoss(a)fhcrc.org" <efoss(a)fhcrc.org> wrote:
>> >> I want to be certain that a print statement is immediately executed.
>> >> Googling around led me to use "$| = 1". Is this correct? Here is an
>> >> example of how I'm using it:
>> >>
>> >> $| = 1;
>> >> $test = 3;
>> >> print "test is $test\n";
>>
JE> Yes, that is the correct use of $|.
>>
>> actually that never uses $| ! the print string ends in newline so it
>> will always be flushed to stdout. $| is meant for when you print text
>> without a newline (say a prompt or partial output or to a socket).

BM> Huh? That's only if the filehandle is line-buffered; AFAIK PerlIO only
BM> supports line-buffering for direct output to a tty.

and the bare print in his code goes to stdout which goes to the tty by
default. hence my comments which assumed those things. otherwise $| is
fairly useless. see my other post for more.

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Peter J. Holzer on
On 2010-03-02 19:29, Uri Guttman <uri(a)StemSystems.com> wrote:
>>>>>> "JE" == J�rgen Exner <jurgenex(a)hotmail.com> writes:
> JE> "efoss(a)fhcrc.org" <efoss(a)fhcrc.org> wrote:
> >> I want to be certain that a print statement is immediately executed.
> >> Googling around led me to use "$| = 1". Is this correct? Here is an
> >> example of how I'm using it:
> >>
> >> $| = 1;
> >> $test = 3;
> >> print "test is $test\n";
>
> JE> Yes, that is the correct use of $|.
>
> actually that never uses $| ! the print string ends in newline so it
> will always be flushed to stdout. $| is meant for when you print text
> without a newline (say a prompt or partial output or to a socket).

No. When the file handle (here STDOUT) doesn't point to a tty, it is
only flushed when the buffer is full not after each line.

> also since the program ends there, you also won't see any difference
> with setting $| or not as stdout gets flushed then as well.

This is correct.

hp
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: Can you compile a perl executable?
Next: strange behavior