Created
June 6, 2014 07:09
-
-
Save mwgamera/0f814ff7ee88127c1456 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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