in reply to finding longest common substring
use strict; use warnings; my @first = qw/ short bigger longest superbig /; my @second = qw/ short longer even longer longest /; my $string = ""; foreach my $item ( @first ) { $string = $item if length $item > length $string and grep { $item eq $_ } @second; } print $string, "\n";
One way to improve the algorithm to scale better may be to keep the arrays ordered in decending order of length so that you could just stop searching on the first match. That would require more overhead at "insertion" time, but much less at searching time.
Dave
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: finding longest common substring
by revdiablo (Prior) on Nov 20, 2003 at 05:53 UTC | |
by davido (Cardinal) on Nov 20, 2003 at 06:37 UTC |