http://qs321.pair.com?node_id=180252

dda has asked for the wisdom of the Perl Monks concerning the following question:

Hello All, I need to convert a value, given in seconds, to string like "1 day, 10 hours, 23 min, 44 sec". I wrote a simple script, but I'd like to check if there is any standard (?) ways to do it, or, at least, more elegant. Or, probably, the code has some bugs?

Code:

use strict; my $idle = 1332443; my ($days, $hours, $min, $sec); $days = round($idle/86400); $idle -= $days*86400; $hours = round($idle/3600); $idle -= $hours*3600; $min = round($idle/60); $idle -= $min*60; $sec = $idle; print "$days days, $hours hours, $min min, $sec sec\n"; sub round { my $value = $_[0]; return (sprintf('%.0f', 2 * $value / 2)); }

Thanks.
--dda