in reply to How do I convert seconds into a readable time?

Here is a method of going back to seconds from a string like "2 days, 6 hours, 32 minutes and 44 seconds":
sub dhms2sec { my $in = shift; $in =~ s/(and|,)//g; $in =~ s/(\w+)s/\1/g; my %y = reverse split(/\s+/,$in); return ($y{'second'}) + ($y{'minute'} * 60) + ($y{'hour'} * 60*60) + ($y{'day'} * 60*60*24); }

Replies are listed 'Best First'.
Re: Answer: How do I convert seconds into a readable time?
by blakem (Monsignor) on Aug 04, 2001 at 04:03 UTC
    The answer and question don't match.... The question is "How do I convert seconds into a readable time?" but the answer given converts readable time into seconds...

    Q: How do I '$seconds => $string'??
    A: Do this '$string => $seconds'!!

    We should change one or the other to get them to match.

    -Blake

    Update After a bit more investigating, I decided that this isn't really an issue. I thought it was the only answer given for the question. Since it is more of a "thats cool, here's how you can do it backwards" post, my complaint isn't really valid. Feel free to remove this node, mr reaper...