The data still isn't really representative though is it!? :P

Just store the file with the single entries as a hash:

#!/usr/bin/perl use strict; use warnings; my $first = "single_records.txt"; my $second = "multiple_records.txt"; warn "tie-ing $first...\n"; tie my %hsh, 'Tie::File::AsHash', $first, split => qr/\s+/ or die "Problem tying %hash: $!"; open (my $fh, '<', $second) || die "Failed to open $second : $!" ## al +ways check for success on fh while (<$fh>){ my $line = chomp($_); my ($id,) = split /\s+/, $line; ## capture id ## compare to tied hsh of single records if (exists$hsh{$id}){ print "$line matched $id : $hsh{$id}\n"; } } ## tidy up close $fh || die "Failed to close $second : $!"; untie %hsh;

Or you can do the other thing i suggestted and hold an array ref of all the lines with a certain id, then print ot all the lines when you see the id in the single record file.

#!/usr/bin/perl use strict; use warnings; my $first = "single_records.txt"; my $second = "multiple_records.txt"; open (my $fh, '<', $second) || die "Failed to open $second : $!" ## al +ways check for success on fh my %second_records = (); while (<$fh>){ my $line = $_; my ($id,) = split /\s+/, $line; ## capture id push @{ $second_records{$id} }, $line; } ## tidy up close $fh || die "Failed to close $second : $!"; ## open single record file and compare open ($fh, '<', $first) || die "Failed to open $first : $!"; while (<$fh>){ my $line = chomp( $_ ); my ($id,) = split /\s+/, $line; ## capture id if ( exists$second_records{$id} ){ print (join '', "$line matches records:\n", @{ $second_records{$id +} }); } } close $fh || die "Failed to close $first : $!";

Hope this helps.

Just a something something...

In reply to Re^3: Comparing two columns by BioLion
in thread Comparing two columns by Nalababu

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.