Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello, first I describe my use case. I need to process a file full of dates with one specific format (%Y.%m.%d,%H:%M). You can see that the precision I will be working with is minutes. Here goes a snippet of the input:

2011.01.13,21:25,1.33508,1.33524,1.33470,1.33494,391 2011.01.13,21:30,1.33494,1.33506,1.33447,1.33453,318 2011.01.13,21:35,1.33453,1.33483,1.33417,1.33434,426 2011.01.13,21:40,1.33434,1.33468,1.33417,1.33467,309 2011.01.13,21:45,1.33471,1.33493,1.33465,1.33465,233 2011.01.13,21:50,1.33465,1.33475,1.33443,1.33463,184 2011.01.13,21:55,1.33463,1.33519,1.33463,1.33493,344 2011.01.13,22:00,1.33494,1.33563,1.33489,1.33524,318 2011.01.13,22:05,1.33524,1.33551,1.33512,1.33549,182
Unfortunately the arithmetical progression pattern you would deduce is not always exact. First, there are no data for weekends (but the hour and minute progression is usually preserved) and second, there are unfortunately some gaps so 13:40 can be followed by 13:50. This apeears to be quite rare but prevents me from handle the data in a nicer way.

And now the goal: I will process the file once by picking 1st date and then comparing next N dates to it until the difference is say 12 hours. (I will definitely not want to compare dates in more detail than hours.) Before each comparing I will do some stuff with the row. After I reach specified time I will proceed with comparing Nth date to next M dates until the difference is again 12 hours and so on.

As I am not very experienced (Perl) coder I first searched CPAN for the right module to use and was quite overwhelmed (and confused) by the rich selection of modules concerning date and time manipulation. Because I will process my file tens of thousands times (each time with different parameters) and it has cca. 1M of rows the time complexity will be quite a concern. Not that my program will be used in any real time apllications but it will be nice if it runs 10 mins instead of 10 hours.

For the date-string parsing part I will probably use DateTime::Format::Strptime so the result will be DateTime object. But what with the comparisons? Should I add specified duration (12 hours) to one object and then compare the two using 'compare' method or first compute the difference in hours and than compare it (as a plain number) with my time interval? Also is there some preferred way how to make use of the fact that for each few hundreds of succesive comparisons one of the objects remains constant or will Perl (or chosen module) do some sort of caching for me?

Last I would like to emphasize again that I can surely do all this somehow but I want to do it also quite fast (but not at too much expense of readability).


In reply to Which DateTime:: module to use? by kejv2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-23 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found