Dan,
  Here's my solution. I'm not capturing the days, hours, minutes, seconds 
as I go, but I'm sure you can see how to if it's really necessary.

#!/usr/bin/perl -w

use strict;
my @list=('3d4h45m12s', '3h', '5h2m');
foreach (@list) {
    my $seconds=0;
    my $string=$_;
    while ($string=~s/(\d+)([dhms])//) {
        $seconds+=24*60*60*$1 if ($2 eq 'd');
        $seconds+=60*60*$1 if ($2 eq 'h');
        $seconds+=60*$1 if ($2 eq 'm');
        $seconds+=$1 if ($2 eq 's');
    }
    print "$_ has $seconds seconds.\n";
}

On Fri, 31 Jan 2003, dan wrote:

> I have a string, which is to represent a length of time, say 3d4h45m12s
> which can be variable, so you may end up with just 3m, or 5h2m, etc. What I
> need to do, is to take this string, and split it up into $days, $hours,
> $minutes etc, and then create that amount of time in seconds, which will
> then be added to the current timestamp to create an expiry time.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to