http://qs1969.pair.com?node_id=249362


in reply to Re: Longest Common Substring
in thread Longest Common Substring

BrowserUK's solution doesn't quite work I tried the following and did not get back what was expected ( " the quick brown fox "):
my $needle = 'i pushed the lazy dog into a creek, the quick brown fox +told me to'; my $haystack = 'the quick brown fox jumps over the lazy dog';
and got back 'the lazy dog' (it works if you reverse the $needle and the $haystack.

But to his credit it seems to work better than String-LCSS-0.10, and he did mention that it might be incomplete (run it both ways, get the longest string and print that, I believe should give you the most right answer, but my tests might also be incomplete).

Where which running the following code:

require String::LCSS; my $needle = 'i pushed the lazy dog into a creek, the quick brown fox +told me to'; my $haystack = 'the quick brown fox jumps over the lazy dog'; my $longest = String::LCSS::lcss ( $needle, $haystack ); print $longest, "\n";
prints only 'lazy dog' (again it works reversing the $needle and the $haystack).

I would use Algorithm-Diff using this part of the documentation as a starting point.

Note: The Author of String-LCSS-0.10 has been notified.

-enlil