Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990541]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2018-04-25 07:09 GMT
Find Nodes?
    Voting Booth?