in reply to Re: making sure a file is not currently being written to
in thread making sure a file is not currently being written to
This can easily happen when Perl buffers some data instead of flushing it to disk. A second file handle opened to a file can't see that buffered data. Your solution of using lexical filehandles won't solve every case, for example the following:
sub write_stuff { open my $fh, '>>', $logfilename or die "Can't append to '$logfilen +ame': $!"; ... check_stuff(); ... }; sub check_stuff { open my $fh, '<', $logfilename or die "Can't read '$logfilename': +$!"; while (<$fh>) { ... }; };
(also see Suffering From Buffering)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: making sure a file is not currently being written to
by moritz (Cardinal) on Jun 05, 2008 at 13:57 UTC |