Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Find common prefix from a list of strings

by AnomalousMonk (Bishop)
on Feb 25, 2014 at 00:43 UTC ( #1076090=note: print w/replies, xml ) Need Help??


in reply to Re: Find common prefix from a list of strings
in thread Find common prefix from a list of strings

Passes same tests as above, but with no capture or length call, might be slightly faster — but no benchmarking done. (I passed all arrays by reference in my testing.)

sub Prefix { my ($ar_strings, ) = @_; return '' unless @$ar_strings; my ($m, $n) = (sort @$ar_strings)[0,-1]; ($m ^ $n) =~ m{ \A \x00* }xms; return substr $m, 0, $+[0]; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1076090]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2020-01-28 20:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?