As suggested above, you want to use a hash-of-arrays (HoA) to store the "sub-*" records from the second flat file, keyed by company name. It would also be useful for the strings from the first flat file to be stored in a simple hash as well (as you read from that file), again keyed by company name. So, somthing like this to read the two files:
my %f1hash; my %f2hash; my $f1 = "company_file.dat"; my $f2 = "other_file.dat"; open( F, $f1 ) or die "can't open $f1: $!"; while (<F>) { chomp; my ( $co, $url, $dir ) = split /\|/; $f1hash{$co} = "$co, $url, $dir<BR>\n"; } close F; open( F, $f2 ) or die "can't open $f2: $!"; while (<F>) { chomp; my ( $co, $url, $dir, $mdir ) = split /, */; push( @{$f2hash{$co}}, " -$co $url $dir<BR>\n"; warn "$f2 contains $co, not found in $f1\n" unless exists( $f1hash +{$co} ); } close F;
Then when you're printing stuff out, do something like this:
for (sort keys %f1hash) { print $f1hash{$_}; print @{$f2hash{$_}}; }

In reply to Re: Flat File Question by graff
in thread Flat File Question by lisaw

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.