File :: Slurp writes file to perl faster

I have a perl script where I am writing a very large log file. I am currently writing my file in the "traditional" Perl mode:

open FILE, ">", 'log.txt';
print FILE $line;
.....
close FILE;

I heard a lot of good things about File :: Slurp when reading in files and how it can significantly improve battery life. My question is, will the File :: Slurp file write my log file faster? I ask because writing the file in perl seems pretty simple, since it is not, I donโ€™t know how File :: Slurp could really optimize it anymore.

+5
source share
2 answers

File::Slurp , , - , , , .

, File::Slurp . , , , , . , - , Tie::File, ,

, read_file . , , , , , ,

. write_file, , ,

. , , , , , , .

, File::Slurp, , .

my @data = do {
  open my $fh, '<', 'my_file' or die $!;
  <$fh>;
};

,

open my $fh, '>', 'out_file' or die $!;
print { $fh } for @data;

. , , , , ,

+8

File::Slurp - . open, while read/write, close read_file write_file.

, , . Perl, C. write_file $file_name, @lines , , .

syswrite . , , . , - .

+8

All Articles