in reply to What is the best way to lock a counter file?

Or, instead of doing all that, just use File::CounterFile.
use File::CounterFile; my $number = File::CounterFile->new("/some/place"); my $next = ++$number;