我如何在Perl字符串中取消反斜杠?

kk.*_*kk. 0 regex perl

我需要将输入地址转换为指定的格式

#!/usr/bin/perl
my $file_path ="\\\abc.com\a\t\temp\L\\";

#---- Help in this regex
$file_path =~ s//\//\/gi;

#---- Output format needed
#$file_path ="\\abc.com\a\t\temp\L\";
printf $file_path;
Run Code Online (Sandbox Code Playgroud)

dax*_*xim 5

我猜你想要标准化一个UNC路径,在这种情况下\,开头的双重保持很重要,以及Ether和KennyTM的答案会产生错误的结果.选择以下任一方法之一.

use File::Spec qw();
print File::Spec->canonpath('\\\abc.com\a\t\temp\L\\');

use URI::file qw();
print URI::file->new('\\\abc.com\a\t\temp\L\\', 'win32')->dir('win32');

__END__
\\abc.com\a\t\temp\L\
Run Code Online (Sandbox Code Playgroud)