Then the sleep() should ensure the pid is not reused within the same tick, so it should still remain unique.
It does depend a bit on the precise sleep() implementation though; possibly safer (and a bit faster) would be:
my $t = time; select(undef, undef, undef, 0.1) while time <= $t; $unique = "$t$$";
It also assumes a monotonically increasing time: if the sysadmin may correct a fast clock backwards, it would be very difficult to cope with. (Note that ntpd will adjust the time in increments of less than a second except when the clock error is "large"; once initially synchronised, a running system corrected by ntpd should never normally skip a full second forwards or backwards.)
Hugo
In reply to Re^4: Need to Generate Unique String
by hv
in thread Need to Generate Unique String
by EchoAngel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |