Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Is there a way to call time() with an increment smaller than seconds?

by BBQ (Curate)
on Apr 23, 2000 at 05:15 UTC ( [id://8643]=perlquestion: print w/replies, xml ) Need Help??

BBQ has asked for the wisdom of the Perl Monks concerning the following question: (dates and times)

For a long time I've used time() as a primary key on small databases just to keep track of records' ages. The problem is: what do I do if I have more than 1 transaction per second? Is there any perlfunc that will let me get less than a full second reply?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: time() smaller than seconds?
by turnstep (Parson) on Apr 23, 2000 at 20:10 UTC
    It's probably easier to just add something else to your primary key than to try and get sub-second responses. A good example is to use:
    $mykey = "$^T$$";
    which sets the key to a combination of the time in seconds and the process ID. This combination will be unique, as long as each time the script is run it generates a single key (e.g. a web script). If the script generates more than one key per second, add a counter:
    $mykey = "$^T$$" . $x++;

    If you do need sub-second times, you can look at the Time::HiRes module, although it may not work on your system, as it uses syscall and gettimeofday(2) in C. Probably easier overall to use the technique above.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://8643]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-29 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found