在路径变量名称中保留空格

时间:2018-07-18 19:11:37

标签: perl typescript

我想打开一个剪辑目录。在目录路径中,两者之间有空格。路径存储在$pathg变量中。

能否告诉我如何打开路径或如何使用path变量在路径中添加转义符?

Path = \\fmsgfxauto4\mediatests$\ATS-MediaTests\Tests\Media\Video\Decoder-Streams\AVC\Suite\VClips\Main_Profile\VC-303-A D-Traffic-AVC-MP\FunctionalTests\V30313_B_D-Traffic_AVC_MP_num_ref_frames_6

代码:

        opendir (CLIPDIR, $pathg) or die "Couldn't open directory $pathg, $!";
        my $isfound = 0;
        while (my $clip = readdir CLIPDIR and $pathg)
        {
            #if($clip =~ /.264$/)
            if(grep{/.264$/ || /.avc$/ || /.26l$/} "$clip")
            {   

1 个答案:

答案 0 :(得分:3)

在双引号字符串文字中,存在的字符中,\$需要转义。

my $pathg = "\\\\fmsgfxauto4\\mediatests\$\\ATS-MediaTests\\Tests\\Media\\Video\\Decoder-Streams\\AVC\\Suite\\VClips\\Main_Profile\\VC-303-A D-Traffic-AVC-MP\\FunctionalTests\\V30313_B_D-Traffic_AVC_MP_num_ref_frames_6";

在单引号字符串文字中,存在的字符中的\可以转义,但是只有在其后跟另一个\时才需要。

my $pathg = '\\\\fmsgfxauto4\\mediatests$\\ATS-MediaTests\\Tests\\Media\\Video\\Decoder-Streams\\AVC\\Suite\\VClips\\Main_Profile\\VC-303-A D-Traffic-AVC-MP\\FunctionalTests\\V30313_B_D-Traffic_AVC_MP_num_ref_frames_6';

my $pathg = '\\\fmsgfxauto4\mediatests$\ATS-MediaTests\Tests\Media\Video\Decoder-Streams\AVC\\Suite\VClips\Main_Profile\VC-303-A D-Traffic-AVC-MP\FunctionalTests\V30313_B_D-Traffic_AVC_MP_num_ref_frames_6';
相关问题