in reply to Measuring Substrings Problem

On first look, id use a hash to flag up positions that match
then just add up the total number of matches...
e.g.

my $s1 = 'GATTACGAGTGGCGCTCGTGTAACGGCA'; # Here are the array of the substrings, note that the number of # substrings may differ from array to array # and length of the substring may vary (defined as a parameter) my @ar = ('GATTACG','GCGCTCG','AACGGCA'); #21 (0,11,21) my @ar2 = ('GATTACG','TTACGAG','CGTGTAA'); #16 my @ar3 = ('TACGAGT','GTGGCGC','GCTCGTG'); #17 print &score($s1,\@ar) , "\n"; print &score($s1,\@ar2) , "\n"; print &score($s1,\@ar3) , "\n"; sub score { my ($str,$array) = @_; my %position_score; for my $frag (@{$array}) { my $idx = index($s1, $frag) + 1; for my $pos ($idx .. $idx + (length($frag) - 1)) { $position_score{$pos} = 1; }; }; my $total_score = 0; for my $score (values %position_score) { $total_score += $score; }; return $total_score; };



This is not a Signature...