in reply to RE: Convert seconds into a formatted ddd:hh:mm:ss string
in thread Convert seconds into a formatted ddd:hh:mm:ss string

Yes yes yes. This is what I was getting at when I said earlier (in the chatterbox) that the code looked "far too regular". ncw, you've done a nice job abstracting the problem.

Also, the use of sprintf there to add the leading 0 is much more perl-ish than the few odd snippets I've seen in this thread of:

$var = "0$var" if $var < 10;
Maybe it's because I first saw that weird-looking code in a Matt Wright script, and it's now tainted me. It scares me to think what other horrors people have now learned from Matt Wright scripts. {grin}

I think for me the problem is that the non-sprintf solution does not scale well. For example, what if you wanted three digits? Do you add another test?

$var = $var < 10 ? "00$var" : $var < 100 ? "0$var" : $var;
No, if I saw code like that in a code review, I'd flag that immediately with "this must be changed before deployment: unmaintainable".

So, get cozy with sprintf: it solves many problems (including the rounding problem discussed a few days ago).

-- Randal L. Schwartz, Perl hacker