Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: How to add minutes with seconds?

by bioMan (Beadle)
on Mar 15, 2006 at 23:04 UTC ( [id://536983]=note: print w/replies, xml ) Need Help??


in reply to Re: How to add minutes with seconds?
in thread How to add minutes with seconds?

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

Replies are listed 'Best First'.
Re^3: How to add minutes with seconds?
by Anonymous Monk on Mar 15, 2006 at 23:15 UTC
    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

        LOL. I should have known better. This is what I get with a bunch of hackers who play golf with their programming language. If I wait long enough I'm sure someone will condense the code down to a single character.

        Mike

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://536983]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found