Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Write large array to file, very slow

by anonymized user 468275 (Curate)
on Aug 20, 2018 at 15:01 UTC ( [id://1220729]=note: print w/replies, xml ) Need Help??


in reply to Write large array to file, very slow

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1220729]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 18:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found