Skip to content

Instantly share code, notes, and snippets.

@mwgamera
Created June 6, 2014 07:09
Show Gist options
  • Select an option

  • Save mwgamera/0f814ff7ee88127c1456 to your computer and use it in GitHub Desktop.

Select an option

Save mwgamera/0f814ff7ee88127c1456 to your computer and use it in GitHub Desktop.
sub lcp(@) {
use List::Util 'reduce';
our ($a, $b);
reduce {
($a ^ $b) =~ m/^\0*+/;
substr $a, 0, $+[0]
} @_
}
sub comp($) {
my $w = shift;
if (local $_ = lcp <\Q$w\E*>) {
$_ .= '/' if -d;
$_ .= ' ' if -f;
return substr $_, length $w
}
return ''
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment