sarvan has asked for the wisdom of the Perl Monks concerning the following question:
Hi there,
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: count the maximum no.of occurence
by jwkrahn (Abbot) on Jun 30, 2011 at 05:34 UTC | |
by sarvan (Sexton) on Jun 30, 2011 at 07:03 UTC | |
by jwkrahn (Abbot) on Jun 30, 2011 at 07:08 UTC | |
by sarvan (Sexton) on Jun 30, 2011 at 07:17 UTC | |
by Anonymous Monk on Jun 30, 2011 at 07:34 UTC | |
| |
Re: count the maximum no.of occurence
by wind (Priest) on Jun 30, 2011 at 06:12 UTC | |
by remiah (Hermit) on Jun 30, 2011 at 12:14 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Back to
Seekers of Perl Wisdom