Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: Longest Common Substring

by Enlil (Parson)
on Apr 09, 2003 at 19:15 UTC ( #249362=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2023-02-05 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (32 votes). Check out past polls.

    Notices?