Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: what is the meaning of $| in perl? (Buffering/autoflush/Unicode/UTF-8 References)

by eyepopslikeamosquito (Archbishop)
on Mar 10, 2014 at 19:13 UTC ( [id://1077742]=note: print w/replies, xml ) Need Help??


in reply to what is the meaning of $| in perl?

Now that you know what $| is, I suggest you don't use it! For Perl 5.8+, instead of your global LOGFILE file handle and:

select(LOGFILE); $| = 1; select(STDOUT);
it is preferable to use a lexical file handle ($logfile say) and then simply:
use IO::Handle; # not needed for Perl 5.14+ # ... $logfile->autoflush();

Note that for Perl 5.14+ you don't need use IO::Handle because:

Before Perl 5.14, lexical filehandles were objects of the IO::Handle class, but you had to load IO::Handle explicitly before you could call methods on them. As of Perl 5.14, lexical filehandles are instances of IO::File and Perl loads IO::File for you.

Extra References Added Later

From On Interfaces and APIs:

Lexical file handles are, for me, the most important feature introduced in Perl 5.6. Those evil old global file handles spawned a host of unfortunate idioms, such as:

select((select($fh), $|=1)[0]);
In terms of a clear and simple interface to perform a simple task (set autoflush on a file handle), it doesn't get much worse than that, a compelling illustration of why keeping state in global variables is just plain evil ...

See also:

PM References

Unicode/UTF-8

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1077742]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-19 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found