LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-06-2012, 10:50 AM   #1
sharky
Member
 
Registered: Oct 2002
Posts: 404

Rep: Reputation: 37
$| in perl


I'm trying to decipher some perl code and there is a statement that I don't understand.

Code:
$|=1;
I've never seen "dollar/pipe" before and google doesn't even seem to understand the search.

Any perl gurus know what this variable in perl represents or how it is used?

Thanks,
 
Old 12-06-2012, 10:54 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
This from the Programming Perl book:
Quote:
autoflush HANDLE EXPR
$OUTPUT_AUTOFLUSH
$AUTOFLUSH
$|

[FHA] If set to true, forces a buffer flush after every print, printf, and write on the currently selected output handle. (We call this command buffering. Contrary to popular belief, setting this variable does not turn off buffering.) The default is false, which on many systems means that STDOUT will be line buffered if output is to the terminal, and block buffered otherwise, even on pipes and sockets. Setting this variable is useful when you are outputting to a pipe, such as when you are running a Perl script under rsh(1) and want to see the output as it's happening. If you have pending, unflushed data in the currently selected filehandle's output buffer when this variable is set to true, that buffer will be immediately flushed as a side-effect of assignment. See the one-argument form of select for examples of controlling buffering on filehandles other than STDOUT. (Mnemonic: when you want your pipes to be piping hot.)
Simply said: Setting $| makes sure that the output is "seen" immediately.

Last edited by druuna; 12-06-2012 at 10:56 AM.
 
1 members found this post helpful.
Old 12-06-2012, 11:07 AM   #3
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: CentOS6
Posts: 267

Rep: Reputation: 57
Here's an example out of one of my scripts:
Code:
 open STUCKLOG, ">$SessionLog" 
        or die "can't open $SessionLog";                #  Set a log file
select(STUCKLOG); $|=1;                                 #  autoflush on

Last edited by david1941; 12-06-2012 at 11:08 AM.
 
Old 12-06-2012, 11:59 AM   #4
sharky
Member
 
Registered: Oct 2002
Posts: 404

Original Poster
Rep: Reputation: 37
That answers my question.

Thanks,
 
Old 12-06-2012, 12:05 PM   #5
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 867
Blog Entries: 2

Rep: Reputation: 216Reputation: 216Reputation: 216
man perlvar
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
install vim via yum thinks perl is required - I build perl 5.14.2 from source rubanek Linux - General 4 05-02-2012 07:42 PM
Print output of a script to screen using Perl/Multiple installation of Perl Modules metallica1973 Linux - General 1 02-17-2011 06:59 PM
Trying to find libmail-mbox-messageparser-perl and libmailtools-perl for Fedora 11 almac58 Linux - Software 4 11-18-2009 04:17 AM
LXer: Installing Eclipse, the Epic Perl plugin and my first Perl GUI program LXer Syndicated Linux News 0 05-08-2009 07:41 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 09:09 PM


All times are GMT -5. The time now is 05:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration