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

7 lines
175 B
Perl
Raw Permalink Normal View History

2015-02-20 00:35:01 -05:00
sub common_prefix {
my $sep = shift;
my $paths = join "\0", map { $_.$sep } @_;
2019-09-12 10:33:56 -07:00
$paths =~ /^ ( [^\0]* ) $sep [^\0]* (?: \0 \1 $sep [^\0]* )* $/x;
2015-02-20 00:35:01 -05:00
return $1;
}