perl - 在路径变量名称中保留空格
问题描述
我想打开一个剪辑目录。在目录路径中,中间有空格。路径存储在$pathg
变量中。
请告诉我如何打开路径或如何使用路径变量在路径中添加转义字符?
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")
{
解决方案
在双引号字符串文字中,存在\
且$
需要转义的字符。
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';
推荐阅读
- python - 网页抓取 html 页面时如何处理非类型对象
- python - 拆分文本时出现“ValueError:int() 的无效文字,基数为 10:''”
- java - 在其连续出现之后返回每个字符
- azure-devops - Azure Dev Ops Pipeline“不再安装此任务。” 错误
- mysql - Helm mysql.initializationFiles 中的 Db 迁移导致 pod 崩溃
- json - 如何将键值对或 JSON 对象传递给 Jenkins?
- javascript - 添加多个弹出标记 - Openlayers 地图
- python - 使用画布绘制 kivy 矩形时出错
- localization - 在常规键盘中输入以 20 为基数的数字系统最直观的方法是什么?
- python - 为什么我不能在我的 Ubuntu 上使用 python3 创建环境?