I hacked this piece of code together. It may work for you or it may not. I think it is pretty straightforward, except for the two-level Schwartzian transform-like anonymous array nesting (
Data::Dumper should help, though)...
#!perl
use strict;
use warnings;
my $string = "EICHENBAUMSCHULE";
my @query = qw/EIC BAUM UMS CHU LE/;
@query = sort { $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] }
grep { $_->[1] > -1 }
map { [$_, index($string, $_), index($string, $_) + length($
+_) - 1] }
@query;
my @matches;
@query
or die "No matches";
my $i = -1;
my $p = -2;
for (@query) {
if ($p + 1 < $_->[1]) {
++$i;
}
push @{$matches[$i]}, $_;
$p = $_->[2];
}
@matches = sort { $b->[0] <=> $a->[0] }
map { [$_->[-1]->[2] - $_->[0]->[1] + 1, $_] }
@matches;
print "Longest continuous match has length $matches[0]->[0]\n\n";
print "$string\n";
for (@{$matches[0]->[1]}) {
print ' ' x $_->[1] . $_->[0] . "\n";
}
Hope this helped.
CombatSquirrel.
Entropy is the tendency of everything going to hell.