Hi JP,

some comments on your code.

On Saturday 02 October 2010 14:25:10 JP wrote:
> Hi all,
> 
> ===[ The script ]=========
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> use Time::HiRes qw(gettimeofday);
> 
> my ( $seconds, $usec, $sec, $min, $hour, $day, $month, $year );

You shouldn't predeclare all these variables here. Declare them when they are 
needed. You also have both $sec and $seconds which is confusing.

> my $time_pointer = 0;
> 
> # (1) Print a current microsecond timestamp
> ( $seconds, $usec ) = gettimeofday();
> ( $sec, $min, $hour ) = localtime( $seconds + $usec / 1000000 -
> $time_pointer );

Why are you doing localtime() on a difference of times? localtime() should 
only be used for seconds since the epoch.


> printf "%02d:%02d:%02d.%06d\n", $hour, $min, $sec, $usec;
> 
> # Print current system date and time
> print `date`;

This is better written as system("date");

> 
> # (2) The current time in microsecond resolution
> ( $seconds, $usec ) = gettimeofday();
> $time_pointer = $seconds + $usec / 1000000;
> 
> # Print a reset'd microsecond timestamp
> ( $seconds, $usec ) = gettimeofday();
> ( $sec, $min, $hour ) = localtime( $seconds + $usec / 1000000 -
> $time_pointer );

Again, this is wrong.

> printf "%02d:%02d:%02d.%06d\n", $hour, $min, $sec, $usec;

There's strftime for that. Also see:

http://perl-begin.org/topics/date-and-time/

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

<rindolf> She's a hot chick. But she smokes.
<go|dfish> She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to