Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by sauoq (Abbot)
on May 11, 2012 at 01:16 UTC ( #969889=note: print w/replies, xml ) Need Help??


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

I would split the strings into character arrays and then count the matches returned by the each_array function of the module List::MoreUtils.

Eeek! No... don't do that. And, for that matter, don't use the approach I gave above either. I just wanted to show how, yes, it could easily be done just by automating the way you might do it by hand.

If you want efficiency, resort to bit twiddling!

Like this:

#!/usr/bin/perl my ($a, $b, $c) = qw (AAATGCCTT AAAAGCGTC AAAGGCGTC); my $bits = ($a ^ $b) | ($b ^ $c); my $c = $bits =~ tr/\0/\0/; print "Similar: $c\n";

:-)

-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re^2: 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://969889]
help
Chatterbox?
LanX sighs ... no idea stupid enough
[choroba]: "Smack My Bitch Up" did, though
[Eily]: that's the internet for you LanX
[Eily]: and I'm pretty sure there's a rule somewhere that states that the stupider the idea, the more likely it is to already have been done
zentara is thinking of moving to Mars to esacpe it all
[LanX]: Zentara eq Dr Manhatten ?
[zentara]: more like Dr. Helion3 :-)

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2017-03-27 15:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.