in reply to Re: Find common prefix from a list of strings
in thread Find common prefix from a list of strings
Depending on the nature of your data this might be a win:sub maxprefix { my $p = shift; for (@_) { chop $p until /^\Q$p/ } return $p; }
sub maxprefix { my $s = reverse shift; my $p = ''; for (@_) { $p .= quotemeta chop $s while /^$p/ } chop $p; return $p; }
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Find common prefix from a list of strings
by ysth (Canon) on Nov 10, 2003 at 03:00 UTC | |
by slink (Initiate) on Feb 22, 2014 at 11:57 UTC | |
by choroba (Cardinal) on Feb 22, 2014 at 12:14 UTC | |
by ysth (Canon) on Feb 23, 2014 at 04:03 UTC | |
|
Re^3: Find common prefix from a list of strings (trailing \)
by tye (Sage) on Nov 10, 2003 at 00:09 UTC | |
by Aristotle (Chancellor) on Nov 10, 2003 at 00:11 UTC | |
|
Re^3: Find common prefix from a list of strings
by simul (Novice) on Feb 28, 2012 at 21:14 UTC |