Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by ZWcarp (Beadle)
on Jul 08, 2011 at 16:38 UTC ( #913387=note: print w/ replies, xml ) Need Help??


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

Sorry this is probably a really dumb question...but.. what is the ^ character doing in this subfunction? I know in regex it means match the first... and its used as a way to negate character class when between brackets...but I cant find its use like shown above.


Comment on Re^3: Hamming Distance Between 2 Strings - Fast(est) Way?
Re^4: Hamming Distance Between 2 Strings - Fast(est) Way?
by BrowserUk (Pope) on Jul 08, 2011 at 19:46 UTC

    ^ 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.
Re^4: Hamming Distance Between 2 Strings - Fast(est) Way?
by Anonymous Monk on Jul 09, 2011 at 04:53 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2014-09-18 20:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (123 votes), past polls