[Asterisk-Users] Strange variable chopping from AGI's
critch at basesys.com
Mon Dec 8 16:23:18 MST 2003
On Mon, 2003-12-08 at 16:28, James Golovich wrote:
> 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
This one will work.
> 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.
this one will not be as accurate because you are loosing any leading
zeroes again. Of course you can combine this with part of the format
above to preserve the zeros to make it work.
> > 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
> 1070917681.837624 1070917682.21563
> Asterisk-Users mailing list
> Asterisk-Users at lists.digium.com
Steven Critchfield <critch at basesys.com>
More information about the asterisk-users