in reply to Re^2: Getting times (weeks, days, hours, minutes, seconds)
in thread Getting times (weeks, days, hours, minutes, seconds)
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,
|
|---|