Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (15)
    As of 2014-04-23 17:30 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (551 votes), past polls