note
vladb
Not a direct answer to your question, but as a suggestion I wanted to point you in the direction of the <a href="http://theoryx5.uwinnipeg.ca/CPAN/data/DateManip/Manip.html">Date::Manip</a> 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 :)
<br><br>
<b>Update:</b><br>
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 ;-)
<code>
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
</code>
And the output the script generates is:
<code>
3d => Day: 3 Hour: 0
3d 2h => Day: 3 Hour: 2
6h => Day: 0 Hour: 6
</code>
<br><br>
_____________________
<code>
# Under Construction
</code>
253226
253226