Skip to content

Instantly share code, notes, and snippets.

@boopsie
Created August 9, 2012 23:50
Show Gist options
  • Save boopsie/3309172 to your computer and use it in GitHub Desktop.
Save boopsie/3309172 to your computer and use it in GitHub Desktop.
Perl Longest Common Prefix
# returns longest common prefix of a list of strings
sub lcp
{
my $match = shift;
substr($match, (($match ^ $_) =~ /^\0*/, $+[0])) = '' for @_;
$match;
}
@lubwen
Copy link

lubwen commented Nov 10, 2022

Is there a version to return the longest common suffix of a list of strings?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment