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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:48:07+00:00 2026-05-17T14:48:07+00:00

I have a text file that is 310MB in size (uncompressed). When using PerlIO::gzip

  • 0

I have a text file that is 310MB in size (uncompressed). When using PerlIO::gzip to open the file and uncompress it into memory, this file easily fills 2GB of RAM before perl runs out of memory.

The file is opened as below:

open FOO, "<:gzip", "file.gz" or die $!;
my @lines = <FOO>;

Obviously, this is a super convenient way to open gzipped files easily in perl, but it takes up a ridiculous amount of space! My next step is to uncompress the file to the HD, read the lines of the file to @lines, operate on @lines, and compress it back. Does anyone have any idea why over 7 times as much memory is consumed when opening a zipped file? Does anyone have an alternate idea as to how I can uncompress this gzipped file into memory without it taking a ridiculous amount of memory?

  • 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-17T14:48:07+00:00Added an answer on May 17, 2026 at 2:48 pm

    When you do:

    my @lines = <FOO>;
    

    you are creating an array with as many elements as there are lines in file. At 100 characters per line, that’s about 3.4 million array entries. There is overhead associated with each array entry which means the memory footprint will be much larger than just the uncompressed size of the file.

    You can avoid slurping and process the file line-by-line. Here is an example:

    C:\Temp> dir file
    2010/10/04  09:18 PM       328,000,000 file
    C:\Temp> dir file.gz
    2010/10/04  09:19 PM         1,112,975 file.gz

    And, indeed,

    #!/usr/bin/perl
    
    use strict; use warnings;
    use autodie;
    use PerlIO::gzip;
    
    open my $foo, '<:gzip', 'file.gz';
    
    while ( my $line = <$foo> ) {
        print ".";
    }
    

    has no problems.

    To get an idea of the memory overhead, note:

    #!/usr/bin/perl
    
    use strict; use warnings;
    use Devel::Size qw( total_size );
    
    my $x = 'x' x 100;
    my @x = ('x' x 100);
    
    printf "Scalar: %d\n", total_size( \$x );
    printf "Array:  %d\n", total_size( \@x );
    

    Output:

    Scalar: 136
    Array:  256
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this text file that I read into a Java application and then
I have a text file that I want to edit using Java. It has
I have a text file that I want to send over the network, this
I have a text file that has a list of directory names like this:
I have a text file that is tab-delimited. How can I separate this string
I have a text file that looks like this: 0000000000000000 0000000000000000 FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 3000000000000000
I have a text file that looks like this: [22/Nov/2011 12:57:58] GET /media/js/jquery-1.4.3.min.js HTTP/1.1
I have a text file that holds values like this: 30 Text 21 Text
i have text file that looks like this: 1 \t a 2 \t b
I have a text file that looks like this: 1 2 4 3 5

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.