The whole print vs. printf conversation seems best left for a completely independent thread.

I didn't realise there was any controversy. It's not even a question of print vs printf but one of

my ($h,$m,$s) = ...; $m = "0$m" if $m < 10; $s = "0$s" if $s < 10; my $dur = "$h:$m:$s";

vs

my ($h,$m,$s) = ...; my $dur = sprintf("%d:%02d:%02d", $h,$m,$s);

Right now, you are creating timestamps like 1:3:43 instead of 1:03:43. printf and sprintf are quite apt at formatting this kind of data, but you don't have to use them. Take your pick.

%d Signed 32/64-bit integer %2d ...space padded (on the left) to occupy (at least) 2 columns %02d ...zero padded (on the left) to occupy (at least) 2 columns

hope that you all aren't disappointed that I just used return instead of printf in my subroutine.

No, separation of calculation and I/O is a good thing. However,

print get_duration('s1');

should be

print get_duration($durations{s1});

or

print get_duration(@{ $durations{s1} });

(with the corresponding changes within get_duration). There's no reason for %durations to be global.

Leap seconds? Where have I been? :)

That post tries to show why DateTime wasn't a good solution for this problem, not how to solve the problem using DateTime. Sounds like it worked.

I have read over several perldocs on objects and barely get it

In short,


In reply to Re^3: Getting times (weeks, days, hours, minutes, seconds) by ikegami
in thread Getting times (weeks, days, hours, minutes, seconds) by Lady_Aleena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.