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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:58:13+00:00 2026-06-14T18:58:13+00:00

I am using 28 files in one perl program. Each file is about 2Mb

  • 0

I am using 28 files in one perl program.
Each file is about 2Mb in size.
I have taken them into 28 arrays. and printing in 28 output files.
Each output file contains all the arrays concatenated , except current file array.
After 11 output files, each of about 70 MB size,
Out of memory! msg is coming .
How to increase the memory limit.

What I tried is :
I closed each file handler after fetching the data into an array. but no use….
Please suggest solutions.

  • 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-14T18:58:14+00:00Added an answer on June 14, 2026 at 6:58 pm

    Assuming that you have four files A B C D, you then want to create four files so that
    File 1 contains B C D,
    File 2 contains A C D,
    File 3 contains A B D, and
    File 4 contains A B C.

    What you are currently doing is loading every file into an array (just using strings would spare a little memory), and then printing each output file consecutively.

    You could also open all output files, then open each input file in sequence and print it to every non-corresponding output file. This keeps only one file in memory at any time.

    use strict; use warnings;
    
    my @in =  qw(A B C D);
    my @out = qw(1 2 3 4);
    
    my @outhandles = map {open my $fh, ">", $_ or die $!; $fh} @out;
    
    for my $i (0 .. $#in) {
       open my $fh, "<", $in[$i] or die $!;
       my $content = do {local $/; <$fh>};
       for my $j (0 .. $#outhandles) {
          print {$outhandles[$j]} $content unless $i == $j;
       }
    }
    

    Memory could be reduced further if you’d say print {$outhandles[$j]} $_ while <$fh> instead of slurping the input files.

    Test

    $ mkdir test; cd test;
    $ for file in {A..D}; do echo $file >$file; done
    $ perl ../script.pl
    $ ls
    1  2  3  4  A  B  C  D
    $ for file in `ls`; do echo == $file; cat $file; done
    == 1
    B
    C
    D
    == 2
    A
    C
    D
    == 3
    A
    B
    D
    == 4
    A
    B
    C
    == A
    A
    == B
    B
    == C
    C
    == D
    D
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using cat *.txt to merge multiple txt files into one, but I
i have a task to transfer text files from one pc to another using
At some point I must have moved files from one location to another using
I'm trying to copy some files from one network share to another using File::Copy.
I am using Perl to print some data read from one file to another.
I'm using one Perl script to prepare Readme text files for my builds. In
I'm writing a combination Java/Perl program that parses XML files into an Oracle SQL
I need to reformat a text file into a PDF. Using Perl, I am
I am currently using c(module_name) to build my Erlang files one by one. How
I'm using ImageMagick to convert some files from one format to another. I was

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.