Anonymous user
Find common directory path: Difference between revisions
→{{header|Perl}}: greatly simplify and clean up the existing solution, while staying true to its spirit
(Added zkl) |
(→{{header|Perl}}: greatly simplify and clean up the existing solution, while staying true to its spirit) |
||
Line 1,107:
=={{header|Perl}}==
A solution that tallies up all potential prefixes from all given paths, and finds the longest one that occurred in all paths:
<lang Perl>use List::Util qw(
sub common_prefix {
my %prefixes;
foreach (@paths) {
}
return first { $prefixes{$_} == @paths } reverse sort keys %prefixes;
}
▲}
# Test and display
Line 1,127 ⟶ 1,126:
/home/user1/tmp/covert/operator
/home/user1/tmp/coven/members);
print
{{out}}
<pre>/home/user1/tmp</pre>
|