[Asterisk-Users] Strange variable chopping from AGI's
James Golovich
james at wwnet.net
Mon Dec 8 15:28:16 MST 2003
On Mon, 8 Dec 2003, John Todd wrote:
>
> AGI's are resulting in unusual behaviors. Can someone please tell me
> if this is my inappropriate use of AGI's, inappropriate use of
> Time::HiRes, or a bug with *:
I'd say inappropriate use on Time::HiRes. Microseconds increment from 0
up to 999,999 and when it passes that mark the second count is incremented
and microseconds is reset to 0.
>
> I call this script twice:
>
> #!/usr/bin/perl
> use Time::HiRes qw( gettimeofday );
> ($seconds, $microseconds) = gettimeofday;
> $hirestime = sprintf("%s","$seconds$microseconds");
> print "SET VARIABLE HIRESTIMESTAMP $hirestime\n";
There are tons of ways to do this right, but here are two of them.
Change your sprintf to:
$hirestime = sprintf("%d%06d", $seconds, $microseconds);
This will make it so that microseconds will always be 6 characters long
or change it to something like:
$hirestime = sprintf("%d.%d", $seconds, $microseconds);
So there will always be a decimal place between seconds and microseconds.
Assuming your later code can deal with it, this is the way I would do it.
> start time end time duration (endtime-starttime)
> 1070917681581683 1070917681942384 360701
> 1070917681666607 1070917681968283 301676
> 1070918477712530 1070918478137011 424481
> 1070917681788671 1070917681998254 209583
> 1070917681837624 107091768221563 -963825913616061 <- error!
Makes sense to me, here is how the numbers look when broken in seconds and
microseconds
1070917681.837624 1070917682.21563
James
More information about the asterisk-users
mailing list