in reply to Getting times (weeks, days, hours, minutes, seconds)
The year and day of week, etc are all meaningless in this context so just throw them away. Leap seconds, leap years don't matter as long as we are talking about data like your example.
The list slice isn't necessary, but I like to line up the left hand side vars so that they are in the order that I use them later. my ($s,$m,$h) would be fine without the slice.#!/usr/bin/perl -w use strict; 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_minutes; my $total_seconds; foreach my $time (@times) { my ($m,$s) = split(':',$time); $total_minutes += $m; $total_seconds += $s; } my ($h,$m,$s) = (gmtime($total_minutes*60+$total_seconds))[2,1,0]; print "$h hours, $m minutes, $s seconds"; #1 hours, 25 minutes, 18 seconds
|
|---|