On May 14, Brian Shoemaker said:
>The Perl 5 book I have says flock function doesn't work in Windows systems.
>
>I don't want to create a lock file each time someone accesses a file and
>then have to delete that lock.
A rather clever way to emulate locking is to use mkdir() and rmdir().
Although it requires you to create a lock file, it's atomic and safe.
sub lock {
1 until mkdir "$_[0].lck", 0777;
$locked{$_[0]}++;
}
sub unlock {
rmdir "$_[0].lck";
delete $locked{$_[0]};
}
END {
rmdir "$_.lck" for keys %locked;
}
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734