Quick Q about $|

Discussion in 'Perl Misc' started by Raj, Jun 25, 2003.

  1. Raj

    Raj Guest

    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
     
    Raj, Jun 25, 2003
    #1
    1. Advertising

  2. Raj

    bd Guest

    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
     
    bd, Jun 25, 2003
    #2
    1. Advertising

  3. * Raj <>:
    > 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/
     
    Matthew Weier O'Phinney, Jun 25, 2003
    #3
  4. Raj

    Ted Zlatanov Guest

    On Wed, 25 Jun 2003, 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
     
    Ted Zlatanov, Jun 25, 2003
    #4
  5. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Matthew Weier O'Phinney <> wrote in
    news:_NiKa.111694$:

    > * Raj <>:
    >> 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+MsuAtMY5qIAnA43
    ta3Xmw0O8TBCxtYAsFaPi9sj
    =ABLm
    -----END PGP SIGNATURE-----
     
    Eric J. Roode, Jun 25, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Song
    Replies:
    0
    Views:
    587
  2. Eric J. Roode
    Replies:
    0
    Views:
    987
    Eric J. Roode
    Jul 19, 2003
  3. jack
    Replies:
    1
    Views:
    919
  4. jack

    Quick perl question 2

    jack, Aug 25, 2003, in forum: Perl
    Replies:
    1
    Views:
    918
  5. JKop
    Replies:
    11
    Views:
    935
Loading...

Share This Page