int to remove fractions. Then remove the minutes from the seconds, and remove the hours from the minutes.
use strict;
use warnings;
my @times = qw( 5:21 8:01 5:37 7:19 5:46 7:44 6:43 7:17 8:02 6:50 7:54
+ 8:44 );
my $total_seconds;
for my $time (@times) {
my ($mins, $secs) = split(/:/, $time);
$total_seconds += $mins*60 + $secs;
}
my $total_minutes = int($total_seconds/60);
$total_seconds -= $total_minutes*60;
my $total_hours = int($total_minutes/60);
$total_minutes -= $total_hours*60;
printf("%s hours, %s minutes, %s seconds\n",
$total_hours,
$total_minutes,
$total_seconds,
);
It is the -> and the printf (which has never made sense to me) that have me stumped.
$t->printf is a method call just like the preceding $t->calc, $t->new_delta and Date::Manip::Delta->new.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.