For some reason I had to ask on IRC what this meant, because it doesn’t google well:
$| = 1;
I don’t know why I didn’t understand that intuitively
At any rate, the answer is:
LeoNerd: No, it forces the currently selected output filehandle not to buffer its output
Related posts:
- Programming in C: Converting an Integer to Binary (int to bin)
- Annoying people with code: A gentle introduction to C# and Mono Part 2 – Data Types
- Annoying people with code: A gentle introduction to C# and Mono
- Annoying people with code: A gentle introduction to C# and Mono Part 3: Creating a GUI (Graphical) Mono / C# Program
- Why?
#1 by Carsten Aulbert on November 7, 2008 - 3:39 pm
Quote
man perlvar
This usually helps a lot
#2 by glandium on November 7, 2008 - 4:01 pm
Quote
It does google well:
http://www.google.com/search?hl=en&q=perl+dollar+pipe
#3 by er on November 7, 2008 - 5:02 pm
Quote
>It does google well
The blogger searched and asked for “$| = 1″, not pipes and dollars.. heck, as a perl newcomer, I wouldn’t even know how dollars and pipes are connected, except when you pay for pipes
#4 by claudio on November 7, 2008 - 5:47 pm
Quote
If you don’t understand the code right away, you should use the readable perl alternatives:
HANDLE->autoflush(EXPR)
or even maybe:
$io = new IO::Handle;
$io->autoflush ( [BOOL] )
Perl is nice because you can read very concise code. However, always prefer readable code.
C.
#5 by Asa on November 7, 2008 - 7:08 pm
Quote
This is one reason I hate using perl.
claudio: I think you missed the point, he clearly didn’t write this code, hes maintaining someone else’s unreadable code. How could he know to use the readable alternative?
#6 by Carsten Aulbert on November 8, 2008 - 4:23 am
Quote
Asa: As the documentation comes with it man perl lists all the pages which might be interesting and since once knows that $| is a variable, perlvar is the natural place to look, right?
#7 by Shane Kerr on November 10, 2008 - 8:54 am
Quote
The first lines of any Perl program should be:
use strict;
use English;
Then you would have seen:
$OUTPUT_AUTOFLUSH = 1;
Which while not self-explanatory is at least something you can paste into a Google search.
#8 by Nicolas Mendoza on June 12, 2009 - 5:41 am
Quote
Ok, so let’s say he’s a total newbie. But he has understood that $ prefix means a variable, and that $| must be something special as it doesn’t look like a regular variable.
Searching in ‘perldoc perltoc’ for $| shows that there is an own perldoc called ‘perlvar’ – searching in ‘perldoc perlvar’ explains what it does, and encourages the use of ‘use English;’
Also, always run your and other’s code thru ‘perlcritic’ and you wouldn’t be allowed to use $| variables:
$ echo “$| = 1;” | perlcritic -4
Module does not end with “1;” at line 1, column 1. Must end with a recognizable true value. (Severity: 4)
Code not contained in explicit package at line 1, column 1. Violates encapsulation. (Severity: 4)
Code before strictures are enabled at line 1, column 1. See page 429 of PBP. (Severity: 5)
Code before warnings are enabled at line 1, column 1. See page 431 of PBP. (Severity: 4)
–> Magic variables should be assigned as “local” at line 1, column 4. See pages 81,82 of PBP. (Severity: 4) <–