in reply to Reading a file before clobbering it for output...
Since we're printing @entries to a file, we don't need to chomp it and put the \n's back. We can just leave them on.
Writing push @entries, <LOG>; would push the entire log onto @entries.# prepend $log_string to @entries my @entries = "$log_string\n"; my $logfile = 'log.txt';
open LOG, $logfile or die "Cannot open $logfile: $!"; push @entries, scalar <LOG> for 1 .. 10; close LOG; open LOG, "> $logfile" or die "Cannot open $logfile: $!"; print LOG @entries; close LOG;
I tested this on windows. You're on your own with flock.
HTH,
|
|---|