这是否足以安全地防止未定义的变量进入我的脚本?正则表达式安全
# Find the name of the VMXF file
$getfilelayout =~ /^ \s+ " (?<vmxf_file> .+\.vmxf) " /xm;
if ("$+{vmxf_file}" eq '') {
$vmxf_file = 'undef';
} else {
$vmxf_file = "$+{vmxf_file}";
$vmxf_file = $ssh_obj->capture("find -name $vmxf_file");
}
如果不是,我还能做什么?
@mu太短,这似乎是访问名为反向引用[Perlretut#命名的反向引用(http://perldoc.perl.org/perlretut.html#Named-backreferences) – stema 2011-05-07 20:35:10
你不应该的方式假设匹配成功了,所以把它放在'if'中。此外,您不必引用您的命名捕获:'$ + {vmxf_file}'检索它就好了。 – tchrist 2011-05-07 23:04:37
@ tchrist,我不必引用捕获?凉。我原本在if语句里面有过匹配,但似乎没有必要,但现在看着你的输入,我可以看到为什么会更好。 – ianc1215 2011-05-08 03:20:35