Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Timeleft subroutine

by kennethk (Abbot)
on Aug 29, 2012 at 19:42 UTC ( #990541=note: print w/replies, xml ) Need Help??

in reply to Timeleft subroutine

When I have to do math, I use DateTime, which includes subtraction. If you want to do the math yourself, it is likely easier to keep it in epoch format, and then only convert for display.

With regards to your code, $sparehour + 1; is a no-op; you probably meant $sparehour = 1;. This would have been flagged by warnings -- see Use strict warnings and diagnostics or die.

Also note that, since you are not using lexical variables (declared with my) your values for $spareminute and $sparehour will leak between calls. You can fix this by just replacing the assignments w/ modifications of the original variables, a la: $minutes -= 1; and $hour -= 1;.

Finally, you have a one-off typo on your return value: you have $minute in place of $minutes in my $baas = $hour + $minute + $seconds;. This would have been caught by strict, and looks like a bug that happened during debugging.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.