Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Timeleft subroutine

by kennethk (Monsignor)
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.


Comment on Re: Timeleft subroutine
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990541]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-08-30 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls