in reply to Re: open FH, "|foo" under modperl2
in thread open FH, "|foo" under modperl2
Someone can squeeze in and modify the log file between the time you've opened the file for append and the time you've thrown a lock on the file. The simple cure for this is to toss in a seek $fh, 0, 2; after the call to flock().I thought "open for append" implied that the system takes care of this, all by itself?
The next test seems to confirm that (Redhat Linux):
Result in the file:#!/usr/local/bin/perl -lw my $file = "test.txt"; unlink $file; if(fork) { open STDOUT, ">>$file" or die "Can't write to file: $!"; $| = 1; print "first"; sleep 3; print "third"; } else { open STDOUT, ">>$file" or die "Can't write to file: $!"; $| = 1; sleep 1; print "second"; }
first second third
|
|---|