Well here's a quick dirty Perl example on converting to miliseconds a string with following format: "Ad Bh Cm Ds" where A, B, C, and D are values for day, hour, minute and second respectively. Order does not matter, but repetition is not contemplated (e.g. only first 'd' appearance will be processed, others will be ignored).
#!/usr/bin/perl
use strict;
my @markers = ('d', 'h', 'm', 's');
my @converter = (24*60*60*1000, 60*60*1000, 60*1000, 1000);
my $string = $ARGV[0];
my $total_ms = 0;
while(@markers)
{
my $cur_mark = shift(@markers);
my $cur_convert = shift(@converter);
if ($string =~ m/$cur_mark/)
{
my $pre = $`;
$pre =~ m/\b/;
$total_ms += $' * $cur_convert;
}
}
print("Total miliseconds = $total_ms\n");
Usage examples:
./foo.pl "2m 2s"
Total miliseconds = 122000
./foo.pl "0.5h 0.5s"
Total miliseconds = 1800500