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 7861535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:46:26+00:00 2026-06-02T22:46:26+00:00

Here is the simple perl script fetching data from SQL. Read data and write

  • 0

Here is the simple perl script fetching data from SQL.
Read data and write on a file OUTFILE, and print the data on screen for every 10000th line.

One thing I am curious is that the printing the data on screen terminates very quickly(in 30 seconds), however, data fetching and writing on a file ends very slowly(30 minutes later).

The amount of data is not large. The output files size is less than 100Mbyte.

while ( my ($a,$b) = $curSqlEid->fetchrow_array() ) 
{
    printf OUTFILE ("%s,%d\n", $a,$b);
    $counter ++;
    if($counter % 10000 == 0){
        printf ("%s,%d\n", $a,$b);
    }
}  
$curSqlEid->finish();
$dbh->disconnect();
close(OUTFILE);
  • 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-06-02T22:46:28+00:00Added an answer on June 2, 2026 at 10:46 pm

    You are suffering from buffering.

    Handles other than STDERR are buffered by default, and most handles use a block buffering. That means Perl will wait until there is 8KB* of data to write before sending anything to the system.

    STDOUT is special. When is attached to a terminal (and only then), it uses a different kind of buffering: line buffering. When using line buffering, the data is flushed every time a newline is encountered in the data to write.

    You can see this by running

    $ perl -e'print "abc"; print "def"; sleep 5; print "\n"; sleep 5;'
    [ 5 seconds pass ]
    abcdef
    [ 5 seconds pass ]
    
    $ perl -e'print "abc"; print "def"; sleep 5; print "\n"; sleep 5;' | cat
    [ 10 seconds pass ]
    abcdef
    

    The solution is to turn off buffering.

    use IO::Handle qw( );  # Not needed on Perl 5.14 or later
    OUTFILE->autoflush(1);
    

    * — 8KB is the default. It can be configured when Perl is compiled. It used to be a non-configurable 4KB until 5.14.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like a simple perl script / sub to read a sql server table
I have a perl script read Excel file and parse using a perl module
I've got a simple Perl script that listens on a network port, accepts data
I am very new to Perl, so please bear with my simple question: Here
I have a quite simple perl script, that in one function does the following:
I have a perl .exe file that I was to run every ten minutes.
I cannot make my Perl script run stable on the server. Here is the
I am trying to write a simple IO::Socket connection in perl. However, I am
I have a perl script that processes millions of lines of performance data, so
I am using the following Perl script to do some simple processing: use strict;

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.