I have a task of parsing huge CSV files with multiple entries for same second of date/time. I need to Process the lines for each second and print it out. I need help with parsing part of the CSV. Sample below.
NAME 6/1/2011 9:30:00 16.76 469898 Q 0 NAME 6/1/2011 9:30:00 16.75 300 Q 0 NAME 6/1/2011 9:30:00 16.75 150 Q 0 NAME 6/1/2011 9:30:01 16.76 756 Q 0 NAME 6/1/2011 9:30:01 16.76 300 Q 0 NAME 6/1/2011 9:30:02 16.76 100 Q 0
The task is to parse lines and computes values high/low first/last value for column 4 for each second.
I am usign Text::CSV_XS to parse CSV but how to get the time/date value from next line to compare with previous line.
while (<FILE>) { $csv->parse($_); my @columns = $csv->fields(); $start_time = str2time($columns[1].' '.$columns[2]); next unless ($curr_time != $start_time) { $exchange = $column[5]; push (@arr1, $column[3]); push (@arr2, $column[4]); push (@arr3, $column[5]); $curr_time = str2time($columns[1].' '.$columns[2]); print "Avg= high= low= in one second=";

In reply to Parse CSV lines and process for each second by capriguy84

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.