From: Rob Das <[EMAIL PROTECTED]>
> I'm trying to merge a whole bunch of files (possibly tens of
> thousands) into one file. Here's my code (with the error checking
> removed for readability):
>
> opendir(INDIR, $indir);
> @logfile=grep(/$mask/i, readdir INDIR);
> closedir(INDIR);
> [EMAIL PROTECTED]; # number of files matching mask
> open(OUTFILE, ">$outdir$outfile");
> for ( $ctr=0; $ctr<$nbrfiles; $ctr++ ) {
> open(INFILE, "$indir$logfile[$ctr]");
> print OUTFILE <INFILE>;
> close(INFILE);
> }
> close(OUTFILE);
As I said before, read the file in chunks, 16KB chunks should be
fine:
opendir(INDIR, $indir);
my @logfile=grep(/$mask/i, readdir INDIR);
closedir(INDIR);
my [EMAIL PROTECTED]; # number of files matching mask
my $buffer='';
open(OUTFILE, ">$outdir$outfile");
for ( $ctr=0; $ctr<$nbrfiles; $ctr++ ) {
open(INFILE, "$indir$logfile[$ctr]");
while (read INFILE, $buffer, 16*1024) {
print OUTFILE $buffer;
}
close(INFILE);
}
close(OUTFILE);
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]