in reply to Re: Write large array to file, very slow
in thread Write large array to file, very slow
The ">>" mode was used precisely because the file is constantly being reopened. But with your ++proposition, the preceding unlink can be removed, to let ">" overwrite the file instead.
Besides, the 3 args version of open with a scalar can be used for many reasons (elegance, safety ...) but at the very least for consistency with the way the input files are opened.
Although Corion's proposition to write the result straight to the file, without the @mergedlogs intermediate variable is probably a good idea as well.my $output_file = "mergedlogs.txt"; open my $output_fh, ">", $output_file or die "Can't open $output_file: + $!"; { local $| = 0; local $\ = "\n"; # Automatically append \n foreach (@mergedlogs) { print $output_fh $_; # "$_\n" copies $_ into a new string before a +ppending \n } } close $output_fh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Write large array to file, very slow
by hippo (Archbishop) on Aug 20, 2018 at 15:24 UTC | |
by Eily (Monsignor) on Aug 20, 2018 at 16:14 UTC | |
by hippo (Archbishop) on Aug 20, 2018 at 18:11 UTC | |
by Eily (Monsignor) on Aug 21, 2018 at 08:29 UTC | |
by hippo (Archbishop) on Aug 21, 2018 at 08:52 UTC |