[英]Perl: Why is this expression not working with the new version of Perl?
I am attempting to run a Perl script, which produces the following error: 我正在尝试运行Perl脚本,该脚本会产生以下错误:
Unescaped left brace in regex is illegal here in regex;
正则表达式中未转义的左大括号在正则表达式中是非法的; marked by <-- HERE in m/^(. )\\$ENV{ <-- HERE (. )}(.*)$/ at /root/cesm1_2_0/scripts/ccsm_utils/Case.template/ConfigCase.pm line 1180. Compilation failed in require at ./create_newcase line 361
在/root/cesm1_2_0/scripts/ccsm_utils/Case.template/ConfigCase.pm第1180行中以<-HERE标记在m /^(.)\\$ ENV {< -HERE (。 )}(。*)$ / 。在./create_newcase行361的要求中编译失败
The offending code is: 令人反感的代码是:
if($text =~/^(.*)\$ENV{(.*)}(.*)$/){
...
}
There was an issue earlier in the code that was due to "using a newer Perl version than that code supports" (see: https://bb.cgd.ucar.edu/machine-configuration-and-generating-domain-file ), so I expect that the regex syntax in Perl has changed. 代码中存在一个较早的问题,该问题是由于“使用了比该代码支持的版本更高的Perl版本”(请参阅: https : //bb.cgd.ucar.edu/machine-configuration-and-generating-domain-file ) ,因此我希望Perl中的regex语法已更改。
Can someone translate this line to be compatible with the current version of Perl? 有人可以翻译此行以与当前版本的Perl兼容吗?
{
is now always treated as a regex metacharacter. {
现在始终被视为正则表达式元字符。 When an unescaped character is illegal, you make it legal by escaping it. 如果未转义的字符是非法的,则可以通过转义使其合法。
$text =~/^(.*)\$ENV\{(.*)}(.*)$/
^---- new character
See https://metacpan.org/pod/distribution/perl/pod/perl5260delta.pod#Unescaped-literal-"{"-characters-in-regular-expression-patterns-are-no-longer-permissible 参见https://metacpan.org/pod/distribution/perl/pod/perl5260delta.pod#Unescaped-literal-"{"-characters-in-regular-expression-patterns-are-no-longer-permissible
尝试这个 :
if ($text =~/^(.*)\$ENV\{(.*)\}(.*)$/) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.