I have program which compares elements of an array with the sentence and prints if it finds the matching.
I m not only comparing single element rather 3 elements at a time.
$str1='It is a guide to action which ensures that the military always +obey the commands of the party.'; chomp($str1); $str2='It is a guide to action that ensures that the military will for +ever heed Party commands is a guide.'; chomp($str2); @arr1=split(/\s+/, $str1); $n=0; for($i=0; $i<$#arr1;$i++) { $t1="$arr1[$i] $arr1[$i+1] $arr1[$i+2]"; if($str2=~/$t1/) { print "$t1\12"; $n++; } } print "\n No of matching is : $n";
What i wanted is, when the three elements from $str1 i.e "is a guide" compared with $str2, it should find two matches, but now it outputs only 1 match. Also i want to count no.of matches for each combination. I.e in this case the countOF(is a guide) is equal to 2. Any suggestion..The output is: It is a is a guide a guide to guide to action ensures that the that the military No of matching is : 6.
In reply to count the maximum no.of occurence by sarvan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |