Actually, the title is not quite true. What I am doing is comparing values from one file against another and based on that comparison, write to a third file. I am starting to go bannas here and I have been keeping on re-writing code numerous times. Sometimes it was working and sometimes it wasn't. Because a pictures is worth a 1000 words, here is a piece of code:
@matched = sort @matched; @phoneBook = sort @phoneBook; foreach (@phoneBook) { @fields = split(',', $_); my $fullname = $fields[0]; $fullname =~ tr/[()]//d; $fullname =~ s/\s+/ /; foreach (@matched) { my @record = split(',', $_); my $lic = $record[$#record]; chomp($lic); my ($lname, $fname) = split('\s+', $record[5]); my $firstn = substr($fname, 0, 2); my $name = "$lname " . "$firstn"; $name =~ tr/[a-z]/A-Z/; if (defined $fullname =~ m/$name/g) { print RESULTS "$record[0],UNKNOWN,$lic,$fullname,$fields[1 +],$fields[2],$fields[3]\n"; } } }
-----------------

What I am doing is comparing names from one file (inner loop) against a bigger file (outer file). If it matches, I simply want to write it out. But it's not happening here. If everything goes fine, I should get about 154 matches. However, I'm getting over 90,000 of them (while the outer loop file contains only about 260 records). Can someone, please tell me what's going on here?

On the same note, then, I want to find out how many records from the inner file do not match the outer. My thinking was "I would simply reverse the loops and do !~." This, however, also seems not to work.

At this point, I would greatly appreciate any hints, directions I should take to resolve it.

Thanks.


In reply to Comparing two files by bman

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.