----- Original Message ----- From: "Jenda Krynicky" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, June 12, 2003 9:17 AM Subject: RE: File not getting written
> 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: And while at it you should also probebly write out in chunks like this: > > 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) { syswrite OUTFILE, $buffer, 16*1024; You should ofcourse check exactly how much you really read and thats how much you'll have to write > } > 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] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]