Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by sauoq (Abbot)
on May 10, 2012 at 17:04 UTC ( #969844=note: print w/ replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969844]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-11-23 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (134 votes), past polls