note
boo_radley
This is a variation on a faq -- see perlfaq 4, "How can I count the number of occurrences of a substring within a string?".<br/>
Using a little eval <i>tr</i>ickery <!-- ha! ha! --> :
<code>
foreach (<DATA>) {
my ($w1, $w2) = split / /, $_;
my %common = ();
foreach ( split //, $w1){
eval "\$foo=\$w2=~tr/$_/$_/" unless exists $common{$_};
$common {$_}=1 if $foo;
}
print "$w1 and $w2 have ", join (", ",sort keys %common)," in common\n";
}
__DATA__
perl monk
help temp
frood hoopysdf
bilbo baggins
jibber jabber
</code>
<br />I wonder about your algorithm in score2, though. It seems to return 1 regardless of actual matches because of the <tt>last</tt>. Perhaps you need a larger/ more complex word set?
225333
225333