Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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?
[shmem]: It's common for some vendors to have column names such as WRSTVG or some other such whizzbang, and another table where these names are mapped to something meaningful depending on how you look at the data
[shmem]: afair in SAP that occurs all the time
[shmem]: afair in SAP that sort of indirection is sprinkled all over the database (for hysterical raisins)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2017-05-25 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?