in reply to sysopen vs. open
Hi,
something like
unless (-e $file) { open(FH,">", "$file") or die $!; }
is almost always wrong as it's open to race conditions.
See Perl Training Australia File test operators, the garden path of race conditions and PerlMonks Avoiding race condition with sysopen for more details.So you're better off avoiding file tests:
use Fcntl; # Open $file for writing unless it already exists sysopen(FH, $file, O_WRONLY|O_EXCL|O_CREAT) or die $!;
HTH,
Thomas
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: sysopen vs. open
by tilly (Archbishop) on May 15, 2009 at 15:25 UTC |