in reply to Re: Time to seconds
in thread Time to seconds

I haven't golfed in a while, so here's Masem's code in one line:
(my $secs = "5H3M17S") =~ s/((\d+)H)?((\d+)M)?((\d+)S)?/3600*$1 + 60*$ +3 + $5/e;
And just to be different:
use strict; my $time = "5H3M17S"; my $secs = 0; my $exponent = 0; map { $secs += $_ * 60 ** $exponent++ } reverse(split(/[HMS]/, $time)) +;

-Matt