dan wrote: > Hi again, > > Sorry for firing many questions at you tonight, this one's probably > simple, but I've racked my brains and can't think of anything for > this one. > > 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.
How about this: sub secs { my %h = reverse split /([a-z])/, shift; $h{s} + $h{m}*60 + $h{h}*3600 + $h{d}*86_400; } print "$_ => ", secs($_), "\n" for qw( 3d4h45m12s 3m 5h2m ); Output: 3d4h45m12s => 276312 3m => 180 5h2m => 18120 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]