Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub find_connection {
- # Find the indexes of the places where words can be
- # combined.
- # A hash array with array hashes will be returned;
- # The key of the hash is word1's index, word2 indexes for the
- # former are contained in the array.
- my ($word1, $word2) = @_;
- my $temp1 = $word1;
- my $index1 = 0;
- my %matches;
- while ($temp1 =~ /[\Q$word2\E]/) {
- my $letter = $&; # The matched letter
- $index1 = $index1 + $-[0] + 1; # The match index for w1
- $temp1 = substr($word1, $index1);
- my $temp2 = $word2;
- my $index2 = 0;
- while ($temp2 =~ /\Q$letter\E/) {
- $index2 = $index2 + $-[0] + 1; # The match index for w2
- $temp2 = substr($word2, $index2);
- push(@{$matches{$index1}}, $index2); # Build a list of matches
- }
- }
- return \%matches;
- }
Add Comment
Please, Sign In to add comment