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
In reply to Re: Re: Re: Find common prefix from a list of strings
by Jenda
in thread Find common prefix from a list of strings
by Albannach
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |