http://www.perlmonks.org?node_id=8643

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.

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

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.