Guest User

Untitled

a guest
Feb 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. sub find_connection {
  2. # Find the indexes of the places where words can be
  3. # combined.
  4. # A hash array with array hashes will be returned;
  5. # The key of the hash is word1's index, word2 indexes for the
  6. # former are contained in the array.
  7. my ($word1, $word2) = @_;
  8. my $temp1 = $word1;
  9. my $index1 = 0;
  10. my %matches;
  11. while ($temp1 =~ /[\Q$word2\E]/) {
  12. my $letter = $&; # The matched letter
  13. $index1 = $index1 + $-[0] + 1; # The match index for w1
  14. $temp1 = substr($word1, $index1);
  15.  
  16. my $temp2 = $word2;
  17. my $index2 = 0;
  18. while ($temp2 =~ /\Q$letter\E/) {
  19. $index2 = $index2 + $-[0] + 1; # The match index for w2
  20. $temp2 = substr($word2, $index2);
  21. push(@{$matches{$index1}}, $index2); # Build a list of matches
  22. }
  23. }
  24. return \%matches;
  25. }
Add Comment
Please, Sign In to add comment