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

Your divisions need to be integer divs, and they arn't. Other then that, I like it.

To make the divs integer you'll need to add the line use integer; as I did. Unfortunately you can't really mix /= and int().

Update:
Tye is right, while you are dealing with floats, they won't have any negative effect, and the printf will convert them to ints correctly. So its all good. ++ for fundflow.

  • Comment on RE: RE: Convert seconds into a formatted ddd:hh:mm:ss string

Replies are listed 'Best First'.
RE: RE: RE: Convert seconds into a formatted ddd:hh:mm:ss string
by fundflow (Chaplain) on Aug 31, 2000 at 02:46 UTC
    If you want to be on the (numerically-) safe side, you can do this:
    $s=$t % 60; $t=($t-$s)/60; $m=$t % 60; $t=($t-$m)/60; $h=$t % 24; $d=($t-$h)/24; $out=sprintf "%03d:%02d:%02d:%02d\n", $d,$h,$m,$s; $out=~s/^0+:|00://g;

    Which is using only integers (assuming $t is integral)
      Well it's not really using integers .. it's still using floating point math, but the decimal portion is always zero. You and I don't care, but the computer processes 1.0 and 1 differently internally. This will make a difference when it comes to overflow and underflow conditions, and just plain execution speed ... integer math is faster, in general.
RE: RE: RE: Convert seconds into a formatted ddd:hh:mm:ss string
by tye (Sage) on Aug 31, 2000 at 02:33 UTC

    In Perl, printf plus "%d" implies int().

            - tye (but my friends call me "Tye")
RE: RE: RE: Convert seconds into a formatted ddd:hh:mm:ss string
by BlaisePascal (Monk) on Aug 31, 2000 at 02:37 UTC
    Does that me my entry needs "use integer" as well?