This is, in concept fairly straightforward. The details depend on information about the file format which you've not provided.

open the master file. open a temp file. read a record, skipping header records, until a significant record or +end of file. Split the significant record (see the split function) into fields. Th +row out all but the last three fields and the key column. loop through the pointers to the child files open each child file read the child file, checking for the key value. write the appropriate data to a temp file. close the child file. repeat until all records in master file have been processed. close the master file. close the temp file open it for appending open the temp file for reading read through the temp file, copying records to the end of the master f +ile.

The key functions to look at are open, split, and grep. Check out Perl's array operators. It probably would be best to use Tie::File, which eliminates the need for opening and closing the master file and keeping a temp file.

In Perl, using negative array indices will count from the end; $array[-1] points to the last element in an array; $array[-2] points to the second to last, etc (symmetry would be nice, but Perl counts array elements from 0, and most computers can't distinguish 0 from -0. Alas.).

emc

Insisting on perfect safety is for people who don't have the balls to live in the real world.

—Mary Shafer, NASA Dryden Flight Research Center

In reply to Re: Line by Line file processing by swampyankee
in thread Line by Line file processing by parekhdip

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.