Hello esteemed PerlMonks,
I have a list of time strings in the HH:MM:SS format. I want to add each to a variable set with localtime and compare it to a timestamp later in the script. I'm having trouble understanding how to add that HH:MM:SS string to the localtime variable.
#! /usr/bin/perl
use Time::Piece;
use strict;
my(@times) = ("00:05:21","00:08:05","00:10:33");
my $startTime = localtime();
print "Start: ", $startTime, $/;
foreach my $t (@times) {
sleep 2;
my $newTime = localtime();
my $ss = $startTime + $t; ### this is where I need advice
if($ss > $newTime){
print "\$ss is greater.\n";
### execute some functions here
}
print "Newtime: ", $newTime, $/;
my $diff = $newTime - $startTime;
print $diff, $/;
The $diff part works but not the addition of $t, how do I add that time to it? Obviously I need to convert it to something Time::Piece understands.
Thank you.