Quick Q about $|

R

Raj

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
 
B

bd

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

Matthew Weier O'Phinney

* Raj said:
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).
 
T

Ted Zlatanov

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
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

$! = 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+MsuAtMY5qIAnA43
ta3Xmw0O8TBCxtYAsFaPi9sj
=ABLm
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top