#!/usr/bin/perl -slw use strict; my $s1 = 'AAAAA'; my $s2 = 'ATCAA'; my $s3 = 'AAAAA'; print "$s1:$s2 hd:", hd( $s1, $s2 ); # will give value 2 print "$s1:$s3 hd:", hd( $s1, $s3 ); # will give value 0 sub hd{ length( $_[ 0 ] ) - ( ( $_[ 0 ] ^ $_[ 1 ] ) =~ tr[\0][\0] ) } __END__ P:\test>500235 AAAAA:ATCAA hd:2 AAAAA:AAAAA hd:0
In reply to Re: Hamming Distance Between 2 Strings - Fast(est) Way?
by BrowserUk
in thread Hamming Distance Between 2 Strings - Fast(est) Way?
by monkfan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |