in reply to Find common prefix from a list of strings
There's a functional module somewhere with reduce in it, I think.
Anyway, you said map, here's my solution...
my @ans = grep {$_} map { my $func = $_; reduce( sub{ my($first, $second) = @_; return ($first eq $second) && $first; } , map(&$func, @data)); } map { my $ctr = $_; sub { my $str = $_; substr($str, 0, $ctr); } } (1..length($data[0])); print pop(@ans), "\n";
I faked a reduce to test it, it works on this dataset.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Find common prefix from a list of strings
by tilly (Archbishop) on Jul 14, 2003 at 22:16 UTC |