http://www.perlmonks.org?node_id=969844


in reply to Is it possible to find the number of matching and non-matching positions in strings using perl code?

Is it possible to use perl code to find the total number of positions where they differ and where they are alike?

Of course.

Here is one straight forward approach:

#!/usr/bin/perl my ($a, $b, $c) = qw (AAATGCCTT AAAAGCGTC AAAGGCGTC); my ($similar, $dissimilar); for (0 .. length($a)-1) { if (substr($a,$_,1) eq substr($b, $_, 1) and substr($b, $_, 1) eq +substr($c, $_, 1)) { print "MATCH"; $similar ++; } else { print "NO MATCH"; $dissimilar ++; } print " at position $_\n"; } print "There were " . $similar . " similar and " . $dissimilar . " dis +similar.\n";
-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re: Is it possible to find the number of matching and non-matching positions in strings using perl code?
  • Download Code