slugger415 has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Comparing time strings from a list of HH:MM:SS times
by hippo (Archbishop) on Aug 10, 2022 at 20:23 UTC | |
by slugger415 (Monk) on Aug 10, 2022 at 22:05 UTC | |
|
Re: Comparing time strings from a list of HH:MM:SS times
by Your Mother (Archbishop) on Aug 10, 2022 at 19:51 UTC | |
by slugger415 (Monk) on Aug 10, 2022 at 22:04 UTC |