RosettaCodeData/Task/Find-common-directory-path/Perl-6/find-common-directory-path-2.pl6
2016-12-05 22:15:40 +01:00

12 lines
405 B
Raku

my $sep := '/';
my @dirs := </home/user1/tmp/coverage/test
/home/user1/tmp/covert/operator
/home/user1/tmp/coven/members>;
my @comps = @dirs.map: { [ .comb(/ $sep [ <!before $sep> . ]* /) ] };
say "The longest common path is ",
gather for 0..* -> $column {
last unless all(@comps[*]»[$column]) eq @comps[0][$column];
take @comps[0][$column] // last;
}