RosettaCodeData/Task/Find-common-directory-path/Perl/find-common-directory-path-1.pl

7 lines
175 B
Perl
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
sub common_prefix {
my $sep = shift;
my $paths = join "\0", map { $_.$sep } @_;
$paths =~ /^ ( [^\0]* ) $sep [^\0]* (?: \0 \1 $sep [^\0]* )* $/x;
return $1;
}