Hi.
I have an application that splitting a large data file into smaller files with a few records each and then saving the files to disk.
For the most part it works well, but in once instance, I am parsing an file with 5000+ records into smaller files of 12 each. It is taking about 20 seconds to save all the 400+ files. My development machine isa little slow, so it will get faster in production, but still I want it to be as fast as possible.
I'm using the basic
foreach my $file (@file) {
my $filename = $file->{'filename'};
my $content = $file->{'content'};
open(FILE, ">$filename")
or die "Can't open $filename $!";
print FILE $content;
close(FILE);
}
My question is, is there some magical module out there, defying my undertanding of how the OS works, to save a bunch of files with only one I/O call? To store them all in memory until they are all ready to be written, and then do it at once, with one open/print/close call?
If not, is there *anything* at all I could do make it faster aside from putting more than 12 records in each file?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.