Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Common Substrings

by Corion (Patriarch)
on Nov 15, 2005 at 10:23 UTC ( [id://508518]=note: print w/replies, xml ) Need Help??


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

    Nice use of xor! And should be better than my loop.

    Still, my concern is breaking multibyte characters.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-23 14:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found