這是否足以安全地防止未定義的變量進入我的腳本?正則表達式安全
# 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