I have a file that i need to read into a database in the following format.
rectype data ID (autoincremented)
REC1 DATAX DATA2 1
REC2 DATA3 DATA4 2
REC3 DATA5 DATA6 3
REC4 DATA7 DATA8 4
RECZ 5
REC1 DATAY DATA2 6
REC2 DATA3 DATA4 7
REC3 DATA5 DATA6 8
REC4 DATA7 DATA8 9
RECZ

AND SO ON. So here is my issue. The data stored at DATAX and DATAY in each group is relevant to the succeeding records and needs to be added to each succeeding record(REC2, REC3, until RECZ, then the next record is a new grouping, so the value has to re-initialized, and would look like this:
REC1 DATAX DATA2 1
REC2 DATA3 DATA4 2 DATAX
REC3 DATA5 DATA6 3 DATAX
REC4 DATA7 DATA8 4 DATAX
RECZ 5 DATAX

REC1 DATAY DATA2 6 (NEW VALUE)
REC2 DATA3 DATA4 7 DATAY
REC3 DATA5 DATA6 8 DATAY
REC4 DATA7 DATA8 9 DATAY
RECZ DATAY

is there a quick perl or MySQL query using fetchrow that will roll-over the values from DATAX to succeeding records until it gets to RECZ and then re-initialize the value for the next group? I can do it either by storing it in the same table or inserting each REC2 into a REC2 table, each REC3 into a REC3 table. One other thing. The number of rows to read are in the millions, so it should be efficient. Thanks.

In reply to Sequential data read in MySQL/Perl by justin423

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.