Dear wise perlmonks, I am getting desperate with this subroutine I am writing: It takes an array containing hours minutes seconds, then it compares the current time to that time and calculates how long it still takes in seconds till that time has arrived. Unfortunately I have not been able to calculate hours correctly because that keeps being wrong and my brain has melted away:(. Or does anyone know a module that could do this for me? Cheers and thank you very much:) Rob
sub timeleft { $hour = (localtime(time))[2]; $minutes = (localtime(time))[1]; $seconds = (localtime(time))[0]; #print "$minutes"; print " Time now is $hour:$minutes:$seconds "; print "Time remaining until $_[0]:$_[1]:$_[2] = "; if ($_[2] == $seconds) {$seconds = 0} if ($_[2] > $seconds) {$seconds = $_[2] - $seconds;} #correct if ($_[2] < $seconds) {$seconds = (60- $seconds) + $_[2]; #correct $spareminute = 1;} #minuteklopt $minutes -= $spareminute; #print "$minutes"; if ($_ [1] == $minutes ) {$minutes = 0; } if ($_ [1] > $minutes ) {$minutes = $_[1] - $minutes; } #correct if ($_ [1] < $minutes ) {$minutes = (60 - $minutes) + $_[1]; #correct $sparehour + 1; } $minuteprint = $minutes; $minutes *= 60; $hour -= $sparehour; if ($_[0] == $hour) {$hour =0;} if ($_[0] > $hour) {$hour =$_[0] - $hour;} if ($_[0] < $hour) {$hour = (24 - $hour) + $_[0] ;} $hourprint = $hour; $hour *= 60; $hour *= 60; print "$hourprint: $minuteprint: $seconds "; $baas = $hour + $minute + $seconds; #$baas = ($hour * 60 * 60) + ($minutes * 60) + $seconds; return $baas }
In reply to Timeleft subroutine by robertw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |