|Syntactic Confectionery Delight|
Unique filenames with Time::HiResby AcidHawk (Vicar)
|on Jul 19, 2004 at 07:43 UTC||Need Help??|
AcidHawk has asked for the
wisdom of the Perl Monks concerning the following question:
Hi, It is has been a wile since I was at the monastery. It's good to be back.
In an attempt to get unique names for files that need to be processed in sequence I turned to Time::Hires. I construct these files from a command line script. I then read the file names (using another script) from a dir and sort them according to the time (The filenames look something like XXX~1090220890.53125.xml . I am using gettimeofday() to get the unique number. To illustrate the issue I face I used the following test code.
The output of which is..
NOT very unique...
The command line interface gets called extremely often and often several for these processes run at the same time. I would really not like to slow down the entire process if I can help it. The only way I can think of doing this is by keeping a number in a file which I lock until I have updated it with a new number. This means that all the other processes have to wait until the file is unlocked.
Anyone have any clever ideas of getting unique numbers fast (some kind of algorithm that includes the time etc...)
Of all the things I've lost in my life, its my mind I miss the most.