in reply to Timeleft subroutine
May I suggest that you convert both times to seconds before you try to compare the times as this makes the comparison much easier?
use feature ":5.14"; use warnings FATAL => qw(all); use strict; sub timeLeft {my ($Hours, $Minutes, $Seconds) = @_; my ($hours, $minutes, $seconds) = @{[localtime(time)]}[2, 1, 0]; my $currentTimeInSeconds = $hours*3600+$minutes*60+$seconds; my $targetTimeInSeconds = $Hours*3600+$Minutes*60+$Seconds; $targetTimeInSeconds > $currentTimeInSeconds ? $targetTimeInSeconds +- $currentTimeInSeconds : undef } say timeLeft(qw(20 50 00));
Produces:
158
|
|---|