Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^4: Generate a unique ID

by BrowserUk (Pope)
on Nov 15, 2010 at 17:25 UTC ( #871514=note: print w/replies, xml ) Need Help??

in reply to Re^3: Generate a unique ID
in thread Generate a unique ID

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://871514]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2018-06-23 21:58 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.