Here's a working example of how to get the current time and how to make your Perl script wait a specified amount of time.
You should be able to do the rest on your own. :-)
#!/usr/bin/perl -w
use strict;
my %TRUE_FALSE =
(
'1' => 'True',
'0' => 'False',
);
my %DAY_OF_WEEK =
(
'0' => 'Sunday',
'1' => 'Monday',
'2' => 'Tuesday',
'3' => 'Wednesday',
'4' => 'Thursday',
'5' => 'Friday',
'6' => 'Saturday',
);
{
&displayTime();
&waitAwhile(3);
&displayTime();
}
exit;
sub displayTime
{
my $nowsse = time;
my ($nowsec,$nowmin,$nowhou,$nowdom,$nowmon,$nowyea,$nowdow,$nowdo
+y,$nowdst) = localtime($nowsse);
$nowyea += 1900;
$nowmon++;
print "---------------------------------------------\n";
my $nowDisplay = sprintf "%04d-%02d-%02d\@%02d:%02d:%02d",
$nowyea, $nowmon, $nowdom, $nowhou, $nowmin, $nowsec
;
print " Time right now: $nowDisplay\n";
print " Day of Week: $DAY_OF_WEEK{$nowdow}\n";
print " Day of Year: $nowdoy\n";
print "Daylight Savings: $TRUE_FALSE{$nowdst}\n";
print "---------------------------------------------\n";
}
sub waitAwhile
{
my ($waitSeconds, @dummy) = @_;
if (!defined $waitSeconds) { $waitSeconds = 0; }
if ($waitSeconds <= 0) { $waitSeconds = 3; }
print "Waiting $waitSeconds seconds\n";
sleep $waitSeconds;
}
__END__
C:\Steve\Dev\PerlMonks\P-2013-07-18@1650-Time-Computation>perl timeCom
+putation.pl
---------------------------------------------
Time right now: 2013-07-18@17:03:10
Day of Week: Thursday
Day of Year: 198
Daylight Savings: True
---------------------------------------------
Waiting 3 seconds
---------------------------------------------
Time right now: 2013-07-18@17:03:13
Day of Week: Thursday
Day of Year: 198
Daylight Savings: True
---------------------------------------------
Have fun!
|