#!/usr/bin/perl # given a list of times in mm:ss format, separated by whitespace, # print the total and average # Sean Brunnock use feature 'say'; use List::Util 'sum'; while () { if (/:/) { # minute:second format my @times = ( $_ =~ /\d:\d\d/g ); my $total=0; for (@times) { my($min,$sec) = split(/:/); $total += $min*60 + $sec; } my $average = int($total/scalar(@times)); printf("%d:%02d total; %d:%.2d average \n", int($total/60), $total % 60, int($average/60), $average % 60); } else { my @nums = split(/,?\s+/, $_); printf("%.2f / %d = %.2f \n", sum(@nums), scalar(@nums), (sum(@nums) / @nums)); } }