[pm-h] Perl merging many large files into one

Michael R. Davis mrdvt92 at yahoo.com
Sun Mar 30 21:00:46 PDT 2014


Perl Folks,
Can anyone tell me if the diamond operator is optimized in a print statement or does it really read the file into memory then print it?
 
perl -e '
use strict;
use warnings;
use Path::Class qw{file};
my @files=qw{X Y Z}; #really large files
my $out=file("out.txt")->openw;
foreach my $file (@files) {
  my $fh=file($file)->openr;
  print $out <$fh>; #does this read to memory then print or does it do something better?
}
'
 
Or do I really need to read line by line something like this...
 
perl -e '
use strict;
use warnings;
use Path::Class qw{file};
my @files=qw{X Y Z}; #really large files
my $out=file("out.txt")->openw;
foreach my $file (@files) {
  my $fh=file($file)->openr;
  my $line;
  print $out $line while ($line=<$fh>);
}
'
 
Thanks,
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/houston/attachments/20140330/80b15301/attachment.html>


More information about the Houston mailing list