sarvan has asked for the wisdom of the Perl Monks concerning the following question:
I have been suggested early on my script. Now the script work in the manner i wanted it. I want a slight modification to that.
output:se warnings; use strict; my $str1 = q/It is a guide to action which ensures that the military a +lways obey the commands of the party./; my $str2 = q/It is a guide to action that ensures that the military wi +ll forever heed Party commands is a guide./; my $n = 0; while ( $str1 =~ /(?=(\S+\s+\S+\s+\S+))/g ) { my $t1 = $1; while ( $str2 =~ /($t1)/g ) { print "$1\n"; $n++; } } print "No of matching is : $n\n";
It is a is a guide is a guide a guide to guide to action ensures that the that the military No of matching is : 7
In addition to this i want to count the maximum no.of occurence for each matched combination(three elements).
i.e for eg. if "is a guide" appears two times in $str2. its maximum reference count is 2. likewise i want to compute for all the combinations.
my $count=($str2=~ tr/$t1//);this counts the no. of times $t1 appeared. But i don't know where to put this inside the loop, so that it can be calculated for all the dynamic values of $t1.
Need help in this.. Thanks..
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: counting inside the loop
by jethro (Monsignor) on Jun 30, 2011 at 13:03 UTC | |
by AnomalousMonk (Archbishop) on Jun 30, 2011 at 15:09 UTC | |
by sarvan (Sexton) on Jul 01, 2011 at 11:09 UTC | |
by Anonymous Monk on Jul 01, 2011 at 11:27 UTC | |
by sarvan (Sexton) on Jul 04, 2011 at 05:19 UTC | |
by Anonymous Monk on Jul 04, 2011 at 06:22 UTC | |
|
Re: counting inside the loop
by rovf (Priest) on Jun 30, 2011 at 12:53 UTC |