Not a direct answer to your question, but as a suggestion I wanted to point you in the direction of the
Date::Manip module. Often in my scripts which dealt with time/date parsing, this module saved my day. It is able to do a lot of date 'magic' but may require some digging in order to understand :)
Update:
Here's a rendition of Ovid's code, but using the Date::Manip module. I agree that using the module for such a simple task may look like an overkill, but I have this feeling your program may have to deal with a lot more date/time manipulation going forward. Even if this is not the case, it's always good to have another way of doing a thing ;-)
use strict;
use Date::Manip;
foreach (<DATA>) {
chomp;
next if /^$/;
my @delta=split(/:/, ParseDateDelta($_));
my ($day) = $delta[3];
my ($hour) = $delta[4];
print "$_\t=>\tDay: $day\tHour: $hour\n";
}
__DATA__
3d
3d 2h
6h
And the output the script generates is:
3d => Day: 3 Hour: 0
3d 2h => Day: 3 Hour: 2
6h => Day: 0 Hour: 6
_____________________
# Under Construction