Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: An efficient way to gather a common portion of several strings' beginningsby atcroft (Abbot) |
on Nov 15, 2015 at 08:22 UTC ( [id://1147719]=note: print w/replies, xml ) | Need Help?? |
I would suggest starting by ordering your array by string length, shortest to longest. Then, take element 0 as your first approximation at the shortest substring and compare it to the same length section (via substr()) to the next string. If they do not match, reduce the test sequence until you arrive at a match, or an empty string. Repeat until you have examined all strings, or have an empty approximation string. Untested code example:
Hope that helps. Update: 2015-11-15
In Section
Seekers of Perl Wisdom
|
|