Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Help with a more precise regex

by vladb (Vicar)
on Apr 25, 2003 at 19:53 UTC ( #253228=note: print w/ replies, xml ) Need Help??


in reply to Help with a more precise regex

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


Comment on Re: Help with a more precise regex
Select or Download Code
Re:^2 Help with a more precise regex
by LogicalChaos (Beadle) on Apr 25, 2003 at 20:57 UTC
    Actually, I won't be using date manipulations much. This is in a ClearQuest project I'm implementing, and all I need to know is that there are 8 hours in a day. The info gathered will be presented in days/hours.

    And, unless I mis-remember, Date::Manip has compiled code, which would make it very difficult for me to place in cqperl (which is derived from ActiveState 5.6.0 perl). I can put in Perl only modules, but wouldn't want to hazzard puting in DLL's (or whatever is used on Windows).

    Thanks for your input,
    LogicalChaos
      Although the solution I was proposing may not be precisely the one you were looking for; I thought it was worth noting for sake of others who might stumble on your post and wonder about alternative ways of doing this. It also appears simpler than the regexp way :)

      There should be absolutely no difficulty in getting Date::Manip to work with cqperl as the module "is written entirely in perl" (quote). Despite of the fact that it may increase the size of your final executable and/or also affect it's run-time speed, there is no other visible harm in using the module. As I had stated, it would be an overkill to use the module to simply decypher date and hour values from the sample input you provided. Nontheless, it does appear cleaner than using raw regexp ;)

      _____________________
      # Under Construction
        I guess you are saying I mis-remembered... Is that what your're saying?

        I was thinking of Date::Calc. And I do thank you for your information. All information is good information, especially when I didn't know it previously.

        Cheers,
        LogicalChaos

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://253228]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2014-09-22 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (178 votes), past polls