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 ILLINOISand another might have:
University of Illinois at ChicagoWhat 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |