Hello again all...
I was trying to add some times up, and well doing it manually was a bit of a pain. I started writing a script and that is when things went badly for me. I can get the raw numbers (with decimals which I don't want). However, I can't get it to do hours, minutes, and seconds in that order.
use strict; use warnings; use List::Util qw(sum); 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); # @times are minutes and seconds. my @times_in_seconds; for my $time (@times) { my @individual_time = split(':',$time); my $seconds = ($individual_time[0] * 60) + $individual_time[1]; push @times_in_seconds,$seconds; } my $total_time_in_seconds = sum(@times_in_seconds); my $total_time_in_minutes = $total_time_in_seconds/60; my $total_time_in_hours = $total_time_in_minutes/60;
I was talking to someone on IRC who gave me the following, however, I can't for the life of me figure out how it works even after looking at the docs for the module.
use Date::Manip; my $t = Date::Manip::Delta->new; for (@times) { $t = $t->calc($t->new_delta($_)); } print $t->printf("%hyh:%02mmm:%02sss\n");
I am very confused. I have never written code that looks like that. It is the -> and the printf (which has never made sense to me) that have me stumped. I haven't written a from scratch script for several months so forgive me if I missed the obvious.
In reply to Getting times (weeks, days, hours, minutes, seconds) by Lady_Aleena
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |