Dear Monks;

I was hoping that someone might be able to help me with a problem. I have a file with 2 lists of data, basically institution names. The data is similar but it is not exactly the same. For instance, in one column might have:

UNIVERSITY OF ILLINOIS
and another might have:
University of Illinois at Chicago
What I am trying to do is split each string into an array of the words. Then I'm wanting to set a criteria of if there are 3 or more matching words, a Y is printed. If not, a N is printed. Below is what I've tried so far. I know that I'm missing something simple but I cannot figure out what. Any suggestions? (btw, I know I should use my in front of the variable and such but I get, um, complained to for lack of another useable term when I do).

!#/usr/bin/perl -w use strict; use warnings; open (IN, "C:/Documents and Settings/devans/Desktop/grant_author_name_ +mapped.txt"); open (OUT, ">C:/Documents and Settings/devans/Desktop/grant_author_nam +e_mapped_.txt"); $count; while (<IN>){ chomp; @t=split(/\t/,$_); $t[2]=~s/\(//gi; $t[2]=~s/\)//gi; $t[8]=~s/\(//gi; $t[8]=~s/\)//gi; ucfirst $t[2]; @b=split(/\ /,$t[8]); @a=split(/\ /,$t[2]); foreach (@a){ if ($_ and exists $b{$_}){ $count++; print "$count\n"; } } if ($count ge 3){ print OUT "$t[1]\t$t[2]\t$t[3]\t$t[4]\tY\t$t[6]\t$t[7]\ +t$t[8]\n"; } else{ print OUT "$t[1]\t$t[2]\t$t[3]\t$t[4]\tN\t$t[6]\t$t[7]\t$ +t[8]\n"; } } close OUT; close IN;

In reply to Compare Arrays with a Count of Matches by de2425

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.