Well... there is always the old date,time and pid combination... that works fine as long as the script doesn't handle multiple messages in a loop.Several people here have mentioned using the "pid", and I just wanted to make sure it's understood that the "$$" special variable always contains the process id. It's a very common idiom to name a temp file something like "/tmp/my_scripts_temp.$$", so that if you've got two instances of the same script running on the same machine at the same time they won't stomp on each other.
Also, I've been known to do things like this:
though this, of course, presumes that you don't have to worry too much about race conditions.my $filename = "~/tmp/temp.$$"; while (-e $filename) { $filename .= '.' . chr(int(rand(25)) + 65); }
In reply to Re^2: What's the best way to avoid name collisions when creating files?
by doom
in thread What's the best way to avoid name collisions when creating files?
by philiph
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |