Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Quick Q about $| (http://www.velocityreviews.com/forums/t869701-quick-q-about.html)

Raj 06-25-2003 02:37 PM

Quick Q about $|
 
Hi,

What does:

$|=1; select(STDOUT);

do? I understand that STDOUT is selected as the default handle, but what
about the bit preceding it?

Thanks,
Raj



bd 06-25-2003 02:51 PM

Re: Quick Q about $|
 
On Wed, 25 Jun 2003 15:37:49 +0100, Raj wrote:

> Hi,
>
> What does:
>
> $|=1; select(STDOUT);
>
> do? I understand that STDOUT is selected as the default handle, but what
> about the bit preceding it?


perldoc perlvar:
$| If set to nonzero, forces a flush right away and after every
write or print on the currently selected output channel.
Default is 0 (regardless of whether the channel is really
buffered by the system or not; $| tells you only whether you've
asked Perl explicitly to flush after each write). STDOUT will
typically be line buffered if output is to the terminal and
block buffered otherwise. Setting this variable is useful pri-
marily when you are outputting to a pipe or socket, such as
when you are running a Perl program under rsh and want to see
the output as it's happening. This has no effect on input
buffering. See "getc" in perlfunc for that. (Mnemonic: when
you want your pipes to be piping hot.)

--
Freenet distribution not available
Journalism is literature in a hurry.
-- Matthew Arnold


Matthew Weier O'Phinney 06-25-2003 03:00 PM

Re: Quick Q about $|
 
* Raj <rajkothary@hotmail.com>:
> What does:
>
> $|=1; select(STDOUT);
>
> do? I understand that STDOUT is selected as the default handle, but what
> about the bit preceding it?


$! = output autoflush. STDOUT is typically line buffered, which means
that there will often be a delay in seeing output if you're piping to
another process (CGI and rsh are two examples). By setting $| to a
non-zero value, you 'turn off' the buffering (actually, it flushes using
fflush(3) after each command that should be piped to STDOUT, usually
print or write).

--
Matthew Weier O'Phinney
http://weierophinney.net/matthew/

Ted Zlatanov 06-25-2003 03:11 PM

Re: Quick Q about $|
 
On Wed, 25 Jun 2003, rajkothary@hotmail.com wrote:
> Hi,
>
> What does:
>
> $|=1; select(STDOUT);
>
> do? I understand that STDOUT is selected as the default handle, but
> what about the bit preceding it?


Try "perldoc perlvar" to find the answer.

Ted

Eric J. Roode 06-25-2003 09:57 PM

Re: Quick Q about $|
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Matthew Weier O'Phinney <matthew@weierophinney.net> wrote in
news:_NiKa.111694$zm1.98342@twister.nyroc.rr.com:

> * Raj <rajkothary@hotmail.com>:
>> What does:
>>
>> $|=1; select(STDOUT);
>>
>> do? I understand that STDOUT is selected as the default handle, but
>> what about the bit preceding it?

>
> $! = output autoflush. STDOUT is typically line buffered, which means
> that there will often be a delay in seeing output if you're piping to
> another process (CGI and rsh are two examples). By setting $| to a
> non-zero value, you 'turn off' the buffering (actually, it flushes
> using fflush(3) after each command that should be piped to STDOUT,
> usually print or write).


Not STDOUT, but rather whatever filehandle was selected at the time $| was
set. The OP's example is sorta backward.

- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPvoaw2PeouIeTNHoEQJJBgCfeHXVj37NOyQVqOyK+MsuAt MY5qIAnA43
ta3Xmw0O8TBCxtYAsFaPi9sj
=ABLm
-----END PGP SIGNATURE-----


All times are GMT. The time now is 08:51 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.