From: Uri Guttman on
>>>>> "PJH" == Peter J Holzer <hjp-usenet2(a)hjp.at> writes:

PJH> 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).

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

but as i keep posting, the code as shown goes to stdout and the tty
unless he redirects it. it is obvious he is looking for the support of
print to the terminal without a newline. that is almost the only real
use for $|.

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

PJH> This is correct.

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: Alan Curry on
In article <878waatkvi.fsf(a)quad.sysarch.com>,
Uri Guttman <uri(a)StemSystems.com> wrote:
|but as i keep posting, the code as shown goes to stdout and the tty
|unless he redirects it. it is obvious he is looking for the support of
|print to the terminal without a newline. that is almost the only real
|use for $|.

My most usual real use for $| is when I've got normal output going to
stdout and verbose trace messages going to stderr, and want to pipe them
both into a pager. $| keeps them in order

--
Alan Curry
From: Peter J. Holzer on
On 2010-03-02 22:32, Uri Guttman <uri(a)StemSystems.com> wrote:
>>>>>> "PJH" == Peter J Holzer <hjp-usenet2(a)hjp.at> writes:
>
> PJH> 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).
>
> PJH> No. When the file handle (here STDOUT) doesn't point to a tty, it is
> PJH> only flushed when the buffer is full not after each line.
>
> but as i keep posting, the code as shown goes to stdout and the tty
> unless he redirects it. it is obvious he is looking for the support of
> print to the terminal

Only because he wrote so in the subject ("printing to the screen"). I
admit that I didn't notice that when I first replied.

I don't think this is obvious from his code at all. As you already
noticed, his code does use a newline (so it's flushed) and it exits
immediately after the print (so it's flushed again).


> without a newline. that is almost the only real use for $|.

I almost never use it for that. Most of the time I use it to get line
buffering for file output (I.e., each print (or printf) writes a whole
line).

hp