First, look at the perlmonks Site How To page for instructions on using the <code> tag when posting your code -- it will retain the indentation and make sure that things like square brackets and angle brackets come through as intended.

Second, consider a different approach. From the data samples you provided, it appears that there is no "key" field that serves to cross-reference the "parent" file with the "child" file. That means you need to be confident about how these two files were created: for each line in the parent file with "C" in the fifth field, exactly one line is written to the "child" file. If this is accurate, then a workable approach could go like this:

You shouldn't have to worry about memory constraints unless the "child" file has hundreds of megabytes of content. The code could end up looking like this:

use strict; open( IN, "ICD_MEAS_child.txt" ) or die "failed to open child data: $! +\n"; my @children = <IN>; # read them all at once; close IN; open( IN, "ICD_MEAS.txt" ) or die "failed to open parent data: $!\n"; while (<IN>) { if ( /,C,/ ) { my $child = shift @children; s/\n/,$child/; # update: added the essential comma s/,/;/g; # update: added this line, as per orig. post } print; } close IN;

In reply to Re^5: Multiple text files by graff
in thread Multiple text files 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.