in reply to Re: Substring Distance Problem
in thread Measuring Substrings Problem

Hi monkey_boy,

Thanks so much for your answer.
However, if there is a repeated substring cases as you mentioned, it should be scored as 4.

Update: With slight modification to your code -by including offset- I managed to accomodate the duplicated case:
# The snippet below returns Score = 4 for (GG,GG)-case sub score { my ($str,$array) = @_; my %position_score; my $offset = 0; for my $frag (@{$array}) { #my $idx = index($str, $frag) + 1; my $idx = index($str, $frag, $offset) + 1; for my $pos ($idx .. $idx + (length($frag) - 1)) { $position_score{$pos} = 1; }; $offset = $idx; };
Regards,
Edward