sub longest_common_substr { # provided you know there are no NULs my $str = join "\0", @_; my $len = 1; my $match; while ($str =~ m{ ([^\0]{$len,}) (?= [^\0]* \0 [^\0]*? \1 ) }xg) { $len = length($match = $1) + 1; } return $match; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Longest common substring
by blakem (Monsignor) on Feb 16, 2002 at 00:29 UTC |