Your excessive use of RAM seems only because you need to process all the files before writing the first line of output. I'd be more inclined to create an empty file and open it in readwrite mode (+< not >>), write the old 10 hexits of the first file just as a placeholder, process each file, skipping subsequent headers and when finished sysseek back to the beginning, overwrite with the new 10 hexits and close up. But you have to limit the functions on the readwrite filehandle to sysseek and syswrite, e.g. (write a load of As, rewind and overwrite 10 Bs at the beginning):
use strict; use warnings; use Fcntl 'SEEK_SET'; system "touch myfile"; open my $fh, '+<', 'myfile'; syswrite $fh, 'A' x 100000, 100000; sysseek $fh, 0, SEEK_SET; syswrite $fh, 'B' x 10, 10, 0; close $fh;

(updated)

One world, one people


In reply to Re: Write large array to file, very slow by anonymized user 468275
in thread Write large array to file, very slow by junebob

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.