in reply to Finding a LCS module on word level
Algorithm::Diff seems to do what you are looking for.
use strict; use warnings; use Algorithm::Diff qw/LCSidx/; my $str1 = "I am trying to find a perl LCS module in perl monk"; my $str2 = "perl monk"; print longest( $str1, $str2 ); sub longest { my @seq1 = split /\s+/, $_[0]; my @seq2 = split /\s+/, $_[1]; my ( $idx1, $idx2 ) = LCSidx( \@seq1, \@seq2 ); my @list = @seq1[@$idx1]; return join( ' ', @list ), '[', join( ',', @$idx1 ), ']'; }
Yields:
perl monk[10,11]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding a LCS module on word level
by almut (Canon) on May 09, 2008 at 15:16 UTC |