Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Find common prefix from a list of strings

by tilly (Archbishop)
on Jul 14, 2003 at 20:17 UTC ( #274144=note: print w/replies, xml ) Need Help??


in reply to Find common prefix from a list of strings

Here is a bad solution just for variety.
my $sep = chr(033); my $str = join $sep, @files; if ($str =~ /^([^$sep]*)[^$sep]*($sep\1[^$sep]*)*\z/s) { print "Common substring: '$1'\n"; } else { die "Pattern unexpectedly failed to match?"; }
Of course it assumes that chr(033) does not appear in the strings...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2020-01-26 22:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?