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.

#! /usr/bin/perl use strict; use warnings; use Time::HiRes ( gettimeofday ); for (my $i = 0; $i <= 10; $i++) { print "$i\tgettimeofday = " . gettimeofday() . "\n"; }
The output of which is..
0 gettimeofday = 1090220890.53125 1 gettimeofday = 1090220890.53125 2 gettimeofday = 1090220890.53125 3 gettimeofday = 1090220890.53125 4 gettimeofday = 1090220890.53125 5 gettimeofday = 1090220890.53125 6 gettimeofday = 1090220890.53125 7 gettimeofday = 1090220890.53125 8 gettimeofday = 1090220890.53125 9 gettimeofday = 1090220890.53125 10 gettimeofday = 1090220890.53125
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.

In reply to Unique filenames with Time::HiRes by AcidHawk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.