Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

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

by ZWcarp (Beadle)
on Jul 08, 2011 at 16:38 UTC ( [id://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?

Replies are listed 'Best First'.
Re^4: Hamming Distance Between 2 Strings - Fast(est) Way?
by BrowserUk (Patriarch) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://913387]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-16 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found