in reply to Re: Time in Milliseconds or NanoSeconds
in thread Time in Milliseconds or NanoSeconds


I mention I do not want to create temporary file because what I am dealing with is a text (one of the elements in XML).
For example say I have an XML file "Filters.xml".
<filterobj> <filter name="abc"/> <filter name="cde"/> </filterobj>
My requirement is to read this XML and do the following.
Convert 'abc' into 'abc.processID.TimeStamp' Convert 'cde' into 'cde.ProcessID.TimeStamp'
Update the above XML file and Update another XML file which is referring to 'abc' and 'cde'.

So there is no temp file concept. I have to create unique names to use in the same file.

The problem now is I am using timestamp in seconds and there could be more than one name generated in the same second with same user provided name. So I asked for some input in creating better unique names and I asked Perl monger's comments on using milli seconds.
Thanks

Replies are listed 'Best First'.
Re^3: Time in Milliseconds or NanoSeconds
by revdiablo (Prior) on Aug 12, 2005 at 07:34 UTC
    The problem now is I am using timestamp in seconds and there could be more than one name generated in the same second with same user provided name.

    How about using a simple incrementing number in this case? You can use sysopen to do this and avoid race conditions:

    use Fcntl; my $username = "..."; my $filename = $username . time; my $inc = 1; my $fh; until (sysopen $fh, $filename.$inc, O_WRONLY|O_CREAT|O_EXCL) { $inc++; } print $fh time, "\n";