in reply to
identifying arbitury patterns in multiple strings
Maybe not the most elegant solution (and I bet rather slow as well)
It finds the longest string that is at the start of every line in the
imput.
use warnings;
use strict;
my %ch;
my $part;
my $lines;
while (<DATA>) {
chomp;
$part="";
map { $part .= $_;
print $part."\n";
$ch{$part}++;
} split (//);
$lines ++;
}
my $max;
foreach (keys (%ch) ) {
if ( ($ch{$_} == $lines) and (length($_) > length($max)) ) {
$max = $_;
}
}
print $max;
__DATA__
abcdefg
abcd
abcd grtf
abcd abd
abcd daf
si_lence