Hi !!
I'm converting a Unix script to Perl on Sun Solaris. The script does message logging with date and time as each step is completed. The time is displayed and the seconds change.
The Unix print looks like this:
print "$(date +'%D %T') Step $STEP completed."
The log looks like this:
07/30/06 17:05:55 Step STEP00 completed.
07/30/06 17:05:56 Step STEP01 completed.
07/30/06 17:05:56 Step STEP02 completed.
07/30/06 17:05:56 Step STEP03 completed.
07/30/06 17:05:57 Step STEP04 completed.
07/30/06 17:05:57 Step STEP05 completed.
07/30/06 17:05:57 Step STEP06 completed.
07/30/06 17:05:58 Step STEP07 completed.
To do the same display, I have to do this before every print to show the changing seconds:
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$mon = $mon + 1;
$year = $year - 100;
my $date = sprintf "%02i/%02i/%02i", $mon, $mday, $year;
my $time = sprintf "%02i:%02i:%02i", $hour, $min, $sec;
print "$date $time Step $STEP completed. \n";
Is there an easier way? It seems so much to do just to display date and time.
Thank you..
I'm converting a Unix script to Perl on Sun Solaris. The script does message logging with date and time as each step is completed. The time is displayed and the seconds change.
The Unix print looks like this:
print "$(date +'%D %T') Step $STEP completed."
The log looks like this:
07/30/06 17:05:55 Step STEP00 completed.
07/30/06 17:05:56 Step STEP01 completed.
07/30/06 17:05:56 Step STEP02 completed.
07/30/06 17:05:56 Step STEP03 completed.
07/30/06 17:05:57 Step STEP04 completed.
07/30/06 17:05:57 Step STEP05 completed.
07/30/06 17:05:57 Step STEP06 completed.
07/30/06 17:05:58 Step STEP07 completed.
To do the same display, I have to do this before every print to show the changing seconds:
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$mon = $mon + 1;
$year = $year - 100;
my $date = sprintf "%02i/%02i/%02i", $mon, $mday, $year;
my $time = sprintf "%02i:%02i:%02i", $hour, $min, $sec;
print "$date $time Step $STEP completed. \n";
Is there an easier way? It seems so much to do just to display date and time.
Thank you..