This code is supposed to check (a) whether two words in a sequence of words
are identical - starting from the beginning and then looping over all words
in sequence - and (b) if not, to what extent they have the same letters in
the same position. This is then used as a basis for computing sequence
resemblance. I'm having troubles with the loop that is supposed to do (b).
(If you have any better ideas to assess sequence resemblance while taking
into account the sequence of words, please let me know!)
use strict;
my (@sum, $i);
my @array = qw(foo bar baz burp);
my $input = "foo bat baz";
my @inputarray = split / /, $input;
# checking
foreach (@inputarray) { print "$_\n";}
print "-------------\n";
foreach (@array) { print "$_\n";}
print "--------------\n";
# end checking
for ($i = 0; $i < @inputarray; $i++) {
#we check all words of the input string in sequence
if ($inputarray[$i] eq $array[$i]) { #if the two words are identical,
percentage is 100
print "identical!\n";#checking
push (@sum, 100); }
else {
my ($percentage, $relevance);
print "not identical: $inputarray[$i] and $array[$i]\n";#checking
# if the two words are not identical
# check to what extent they have the same letters in the same positions
my @wordarray = split //, $inputarray[$i];
my @otherwordarray = split //, $array[$i];
for ($i = 0; $i < @wordarray; $i++) {
if ($wordarray[$i] eq $otherwordarray[$i])
{
print "match $wordarray[$i] and
$otherwordarray[$i]\n";#checking
$relevance++; }
}
print "relevance: $relevance\n";#checking
$percentage = (100*$relevance)/@otherwordarray;
print "percent of letters in same position:
$percentage\n";#checking
push (@sum, $percentage);
}
}
my $sum;
foreach (@sum) {
print "$_\n";#checking
$sum += $_; }
$sum = $sum/@sum;
print "RELEVANCE: $sum\n";#checking
Output:
foo
bat
baz
-------------
foo
bar
baz
burp
--------------
identical!
not identical: bat and bar
match b and b
match a and a
relevance: 2
percent of letters in same position: 66.6666666666667
100
66.6666666666667
RELEVANCE: 83.3333333333333
Problem: The loop should go on to examine "baz" after a resemblance between
"bat" and "bar" was computed, but it doesn't seem to.
Any clues?
Birgit Kellner
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]