in reply to match and mismatch
There is a neat trick for finding difference between similar equal length ASCII strings: xor them together and any non-zero bytes are different. Consider:
use strict; use warnings; my $one= "AGCTGATCGAGCTAGTACCCTAGCTC"; my $two= "AGCTGATCGAGCTAGTACCCTATCTC"; my $diff = $one ^ $two; $diff =~ tr/\0/x/c; my $start = -1; while (-1 < ($start = index $diff, 'x', ++$start)) { print "Difference at $start\n"; }
Prints:
Difference at 22
The tr/// changes non-zero bytes to x. The while loop then uses index to search through the difference string for the x bytes and reports their index (0 based position).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: match and mismatch
by johngg (Canon) on Nov 14, 2008 at 10:35 UTC | |
|
Re^2: match and mismatch
by heidi (Sexton) on Nov 17, 2008 at 03:25 UTC | |
by bart (Canon) on Nov 17, 2008 at 03:57 UTC | |
by heidi (Sexton) on Nov 17, 2008 at 04:58 UTC | |
by Anonymous Monk on Feb 10, 2017 at 05:00 UTC |