You probably want to use a simple foreach like you are doing. It sounds like you've got the hard parts figured out. Basically, in your loop, first use your if statement to see whether your row contains a SYSTEM header. If it does, set a variable to contain the description which appeared in the row above. Something like this pseudocode:
my $current_description; foreach $row (@rows) { if ($row is a 'SYSTEM' row) { $current_description = (description from 2 rows above); } if ($row is a part number) { insert into database ($part_number, $current_description) } }
That way, you're just inserting all the parts and descriptions, and all you do is change your description whenever you hit a SYSTEM row. If you need more information than just a description, you can use a hash structure instead of a scalar, but the concept is the same.

UPDATE: Argh, another double post! As ELISHEVA says below, go back to your original post and look at the answers there. It's not nice to have me spend my time helping you when I don't know that others have already given you good advice on the same topic.

In reply to Re: Iterative Subroutine Approach Question by bellaire
in thread Iterative Subroutine Approach Question by Anonymous Monk

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.