in reply to Common Substrings
How about
sub common { if ( $_[0] eq $_[1] ) { return( $_[0], "", "" ); } else { use bytes; my $x = $_[0] ^ $_[1]; $x =~ m!^(\x00*)!; my $pos = length $1; my ( $len0, $len1 ) = ( length($_[0])-$pos, length($_[1])-$pos ) +; return( unpack("a${pos}", $_[0]), unpack("x${pos}a*", $_[0]), unpack("x${pos}a*", $_[1]), ); } }
That way you scan the two strings, but you do it in C instead of doing it in Perl.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Common Substrings
by Anonymous Monk on Nov 15, 2005 at 10:31 UTC |