Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6093835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:36:24+00:00 2026-05-23T12:36:24+00:00

I was refactoring some old code (by other people) and I came across the

  • 0

I was refactoring some old code (by other people) and I came across the following at the top of some CGI scripts:

#Turn on output buffering
local $| = 1;

perlcritic as usual unhelpfully points out the obvious : “Magic punctuation used”. Are there any alternatives to this or perlcritic is just grumpy?

Furthermore, on closer inspection. I think the code is wrong.

If I’m not mistaken, it means exactly the opposite from what the comment says. It turns off the output buffering. My memory is a little bit rusty and I can’t seem to find the Perl documentation that describes this magic punctuation. The scripts run in mod_perl.

Does messing around with Perl’s buffering behavior desirable and results in any performance gain? Most of the stuff written about this comes from the early part of the first decade of the 21st century. Is this still even a valid good practice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:36:25+00:00Added an answer on May 23, 2026 at 12:36 pm

    Your question seems a bit scattered, but I’ll try my best to answer thoroughly.

    You want to read perldoc pervar. The relevant section says:

       $|      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 primarily 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.  See "select" in perldoc
               on how to select the output channel.  See also IO::Handle. (Mnemonic: when you want your pipes to be piping hot.)
    

    So yes, the comment is incorrect. Setting $| = 1 does indeed disable buffering, not turn it on.

    As for performance, the reason output buffering is enabled by default is because this improves performance–even in 2011–and probably until the end of time, unless quantum I/O somehow changes the way we understand I/O entirely.

    The reasons to disable output buffering are not to improve performance, but to change some other behavior at the expense of performance.

    Since I have no idea what your code does, I cannot speculate as to its reason for wanting to disable output buffering.

    Some (but by no means all) possible reasons to disable output buffering:

    • You’re writing to a socket or pipe, and the other end expects an immediate response.
    • You’re writing status updates to the console, and want the user to see them immediately, not at the end of a line. This is especially common when you output a period after each of many operations, etc.
    • For a CGI script, you may want the browser to display some of the HTML output before processing has finished.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whilst refactoring some code I came across some getter methods that returns a std::string.
Whilst refactoring some old code I realised that a particular header file was full
While refactoring some old code I have stripped out a number of public methods
I'm refactoring some old JavaScript code and there's a lot of DOM manipulation going
I'm currently refactoring/tidying up some old C code used in a C++ project, and
I am currently refactoring some of my old code that is pretty terrible. I
Whilst refactoring some legacy C++ code I found that I could potentially remove some
I'm refactoring some PHP code and discovered that certain nested combinations of if ()
I am refactoring some MFC code that is littered with ASSERT statements, and in
I'm refactoring some code I inherited from a long-gone developer, and I find this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.