perlquestion
kejv2
<p>
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:
<code>
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
</code>
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.
</p>
<p>
And now the goal: I will process the file <b>once</b> 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.
</p>
<p>
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.
</p>
<p>
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?
</p>
<p>Last I would like to emphasize again that I can surely do all this <b>somehow</b> but I want to do it also quite <b>fast</b> (but not at too much expense of readability).
</p>