in reply to Re: Re: Find common prefix from a list of strings
in thread Find common prefix from a list of strings
Uh oh ... I wanted to point out that your solution is wrong, found a conter example and ... it broke my code as well :-(
Here is a fixed solution:
@files = qw(model4run1 model5run1); #@files = qw(model4run1 model2run1 model4run2 model1run1); my $first = shift(@files); my $and = $first; my $or = $first; foreach (@files) { $and &= $_; $or |= $_; } my $combined = $and ^ $or; $combined =~ s/[^\x00].*//; my $prefix = substr($first, 0, length($combined)); print qq{Prefix is "$prefix"};
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Find common prefix from a list of strings
by antirice (Priest) on Jul 15, 2003 at 00:46 UTC | |
by Jenda (Abbot) on Jul 15, 2003 at 12:09 UTC | |
|
Re: Re: Re: Re: Find common prefix from a list of strings
by fletcher_the_dog (Friar) on Jul 15, 2003 at 14:29 UTC |