in reply to "unique" filename?
In a pinch, use something like this:
But of course, there's still a race condition. A more secure solution would be to take advantage of sysopen and O_EXCL to iterate through filenames:$num = 12345; $dir = "/some/dir/"; $num++ while -e "$dir/$num"; open(F, ">$dir/$num") or die ...
Once you start adding all of the bells and whistles, though, you're just re-implementing IO::File new_tmpfile.use Fcntl; use FileHandle; $num++ while !sysopen(F, "$dir/$num", O_EXCL|O_CREAT, 0777) && $! eq " +File exists"; die "$dir/$num: $!" if $!;
|
|---|