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.

# prepend $log_string to @entries my @entries = "$log_string\n"; my $logfile = 'log.txt';
Writing push @entries, <LOG>; would push the entire log onto @entries.
Writing push @entries, scalar <LOG>; would push one line of the log onto @entries.
Adding for 1 .. 10; adds 10 lines of the log to @entries.
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,
Charles K. Clarkson