Need to capture the exact date/time the connection is made because a file will be created with the date/combo as part of the filename.
Using Time::HiRes to ensure unique filenames is probably overkill. It would be easier and cleaner to simply increment a counter for each connection created within the same second. I would use something like:
{
my ($t,$c);
sub unique_timestamp {
my $time = time;
$c++;
$c = 0 unless $time == $t;
$t = $time;
my ($s,$m,$h,$D,$M,$Y) = (localtime($time))[0..5];
sprintf "%04d%02d%02d%02d%02d%02d%03d",
$Y+1900, $M+1, $D, $h, $m, $s, $c;
}
}
# To see that work...
for (1..100) {
print unique_timestamp, "\n";
sleep rand 2;
}
If you could have more than 1000 connections in a second, you may wish to increase that %03d in the sprintf to %04d or something. This code avoids the use of a module and parsing out fractional seconds. It also results in sequential unique stamps that are the same length.
-sauoq
"My two cents aren't worth a dime.";
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.