Created
August 9, 2012 23:50
-
-
Save boopsie/3309172 to your computer and use it in GitHub Desktop.
Perl Longest Common Prefix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# returns longest common prefix of a list of strings | |
sub lcp | |
{ | |
my $match = shift; | |
substr($match, (($match ^ $_) =~ /^\0*/, $+[0])) = '' for @_; | |
$match; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a version to return the longest common suffix of a list of strings?