Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^4: Hamming Distance Between 2 Strings - Fast(est) Way?

by BrowserUk (Patriarch)
on Jul 08, 2011 at 19:46 UTC ( [id://913409]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Hamming Distance Between 2 Strings - Fast(est) Way?
in thread Hamming Distance Between 2 Strings - Fast(est) Way?

^ in this case is bitwise-OR.

When you bitwise-OR two strings, where the bytes in the two strings are the same, the byte in the resultant string will be chr(0); when they are different, the results will be non-chr(0). This allows you to count the number of differences in two strings very quickly:

$seq1 = 'ACGTACGTACGTACGT';; $seq2 = 'TCGATCGATCGATCGA';; print ( $seq1 ^ $seq2 );; § §§ §§ §§ § print length( $seq1) - ( $seq1 ^ $seq2 ) =~ tr[\0][\0];; 8

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-03-29 02:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found