It's not clear to me why you need the "uniqueness" at all?

The requirement came out of a real situation.

A bug caused the program to crash and leave behind some of its temporary files. I was away from the machine at the time. When I came back, I re-ran the program having made a few changes--including correcting the problem that caused the crash I hadn't noticed happen--and the second phase of the code mixed up the content of the previous run with those of the current run. I spent a long time trying to work out why the final output was completely screwed up before noticing that the previous run had terminated badly whilst reviewing the debug trace in the console buffer.

Imagine how annoying it would be if your system sort utility mixed up spill files from an interrupted run with those generated by the current run.

Any mechanism that relies upon correct clean-up of either the files themselves or semaphore files is vulnerable to the same issue.

For the PID + timestamp to fail, the system would have to issue exactly the same PID at exactly the same time--within the resolution of the timestamp granularity. The combined value suitably encoded (hex or base64) will be used as the prefix supplied to tempname() to generate the names for the temp. files.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

In reply to Re^4: Generate a unique ID by BrowserUk
in thread Generate a unique ID by BrowserUk

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.