Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

The Date::Calc module's Date_to_Time will convert your date/time information almost directly, with the addition of a trailing 0 for seconds. Given this, and your task, perhaps the following will assist your coding:

use Modern::Perl; use Date::Calc qw/Date_to_Time/; my $duration = 10 * 60; my $fileName = 'data.txt'; open my $fh, '<', $fileName or die "Unable to open file: $!"; for ( ; ; ) { my ( $first, @lines ); while ( my $line = <$fh> ) { my ( $date, $time, $values ) = split ',', $line, 3; my @dateTime = "$date $time 0" =~ /(\d+)/g; my $timeInSecs = Date_to_Time @dateTime; $first = $timeInSecs unless $first; push @lines, "$timeInSecs\t$values"; last if $timeInSecs - $first >= $duration; } # Start work with chunk of lines in array # do { /(\S+)\t(\S+)/; say "Seconds: $1; Values: $2" } for @lines; say '----------'; # # End work with chunk of lines in array last if eof $fh; } close $fh;

Output (lines were added to your original data set):

Seconds: 1294953900; Values: 1.33508,1.33524,1.33470,1.33494,391 Seconds: 1294954020; Values: 1.33508,1.33524,1.33470,1.33494,391 Seconds: 1294954200; Values: 1.33494,1.33506,1.33447,1.33453,318 Seconds: 1294954320; Values: 1.33494,1.33506,1.33447,1.33453,318 Seconds: 1294954500; Values: 1.33453,1.33483,1.33417,1.33434,426 ---------- Seconds: 1294954620; Values: 1.33453,1.33483,1.33417,1.33434,426 Seconds: 1294954800; Values: 1.33434,1.33468,1.33417,1.33467,309 Seconds: 1294954920; Values: 1.33434,1.33468,1.33417,1.33467,309 Seconds: 1294955100; Values: 1.33471,1.33493,1.33465,1.33465,233 Seconds: 1294955220; Values: 1.33434,1.33468,1.33417,1.33467,309 ---------- Seconds: 1294955400; Values: 1.33465,1.33475,1.33443,1.33463,184 Seconds: 1294955520; Values: 1.33465,1.33475,1.33443,1.33463,184 Seconds: 1294955700; Values: 1.33463,1.33519,1.33463,1.33493,344 Seconds: 1294955820; Values: 1.33465,1.33475,1.33443,1.33463,184 Seconds: 1294956000; Values: 1.33494,1.33563,1.33489,1.33524,318 ---------- Seconds: 1294956120; Values: 1.33494,1.33563,1.33489,1.33524,318 Seconds: 1294956300; Values: 1.33524,1.33551,1.33512,1.33549,182 ----------

The script will read in N lines from a data file, based upon the value of $duration, which, in this case, is set to 10 minutes (always set $duration to seconds). The output shows clusters of lines within 10 minute intervals. The routine may grab one line beyond the duration, but hopefully that data granularity is sufficient for your analysis.

Not knowing how you want to work with your data, the push @lines, "$timeInSecs\t$values"; line can be changed to push only the raw lines (or whatever you may need) onto the array @lines.

Hope this helps!


In reply to Re: Which DateTime:: module to use? by Kenosis
in thread 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 meditating upon the Monastery: (8)
    As of 2014-12-26 05:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (165 votes), past polls