Home > Archive > PERL Beginners > January 2006 > time()
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Rick Triplett 2006-01-21, 6:56 pm |
| I time stamp a lot of my file interactions with $stamp = time(), but
about one out of a hundred or so stamps gives me the system epoch
date instead of the true date. Correct me if I'm wrong, but I am
assuming that the time() function makes a system call, and that it
can be checked for failure. To do this, I've written the following
"try again" routine
sub get_time {
if ($stamp = time() ) {return}
else {$stamp = time()}
$stamp;
}
I could also add some elsif's to repeat the try again, or a short
sleep between tries, if that would help. Or maybe I need a whole new
approach? I can try this out, but it will take w s to get enough
results to see if it works. Any suggestions would be greatly
appreciated.
Rick Triplett
| |
| usenet@DavidFilmer.com 2006-01-21, 6:56 pm |
| Rick Triplett wrote:
> about one out of a hundred or so stamps gives me the system epoch
> date instead of the true date.
I don't believe you. I think something else is going on (I suspect
something is being assigned undef somewhere), and your efforts to
compensate for the behavior are mis-directed (and causing you to not
find the true source of your problem).
So prove to me (and, more importantly, to yourself) that what you say
happens really happens. Run this script, which builds an array of a
hundred THOUSAND time()s and reports the largest/smallest value. Those
values should be very close (the same, or maybe one or two seconds
different).
#!/usr/bin/perl
use strict; use warnings;
use List::Util qw{max min};
my @times;
push @times, time() for (1..100_000);
print min (@times), "\n";
print max (@times), "\n";
__END__
| |
| usenet@DavidFilmer.com 2006-01-21, 6:56 pm |
| usenet@DavidFilmer.com wrote:
> Run this script...
Or you can do the same thing this way, if you don't have List::Util
installed (and you REALLY should, BTW). This version prints all the
different values that time() returns (you should only see one value, or
maybe two or three sequential values):
#!/usr/bin/perl
use strict; use warnings;
my %time;
$time{ time() }++ for (1..100_000);
print map {"$_\n"} sort keys %time;
__END__
--
http://DavidFilmer.com
| |
| Tom Phoenix 2006-01-21, 9:55 pm |
| On 1/21/06, Rick Triplett <ricktrip@reason.net> wrote:
> I time stamp a lot of my file interactions with $stamp =3D time(), but
> about one out of a hundred or so stamps gives me the system epoch
> date instead of the true date.
If your time() function ever gives you the epoch (zero or undef),
that's a bug. Can you reproduce this?
> Correct me if I'm wrong, but I am
> assuming that the time() function makes a system call, and that it
> can be checked for failure.
Well.... the underlying system call could fail, but if perl isn't
taking care of that for you, that's a bug. You shouldn't have to work
around it. Reproduce it, then report it with perlbug.
> To do this, I've written the following
> "try again" routine
>
> sub get_time {
> if ($stamp =3D time() ) {return}
> else {$stamp =3D time()}
> $stamp;
> }
$stamp =3D time until $stamp;
....but that shouldn't be necessary. Hope this helps!
--Tom Phoenix
Stonehenge Perl Training
|
|
|
|
|