in reply to How to add minutes with seconds?

perl -e 'my @a = qw(1:08 2:53 1:00); foreach(@a){($min, $sec)=split /: +/;$time+=($min*60)+$sec}; print $time=int($time/60).":".(sprintf "%.2 +d", $time%60)."\n"'

Replies are listed 'Best First'.
Re^2: How to add minutes with seconds?
by bioMan (Beadle) on Mar 15, 2006 at 23:04 UTC

    I believe you can further reduce the code to:

    perl -e 'my @a = qw(1:08 2:53 1:00); foreach(@a){($min, $sec)=split /: +/;$time+=( +$min*60)+$sec}; print int($time/60).":".(sprintf "%.2d", $time%60)."\ +n"'

    It only saves six keystrokes; however, I do love the economy of your code.

    Mike

      perl -e 'for (@ARGV) { /(d+):(\d+)/; $time += $1*60 + $2 } printf "%d:%.2d\n", $time/60, $time%60' 1:08 2:53 1:00
        perl -e '$_+=$a*60+$b while($a,$b)=split/:/,shift; printf"%d:%.2d\n",$ +_/60,$_%60' 1:08 2:53 1:00