On Sep 21, John Edwards said:
>do {
> $artikelID = &newID;
>} until (! -e $ARTIKEL_DIR.$artikelID);
That produces a race condition. Between the checking for the existence of
the file, and the opening of the file itself, the file COULD be created.
I suggest the use of the sysopen() function.
Assuming you want to open the file for writing to:
use Fcntl qw( O_WRONLY O_CREAT O_EXCL );
1 until sysopen(FILE, $name = newID(), O_WRONLY | O_CREAT | O_EXCL);
The O_CREAT and O_EXCL flags mean that the file MUST not exist -- the
sysopen() call does not involve a race condition, though, so this is safe.
For more, read
perldoc -f sysopen
man open
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]