Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 scrutinizing the Monastery: (3)
As of 2014-09-21 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (167 votes), past polls