Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Perl脚本停止。错误:Can';找不到unicode属性定义ASCII_Regex_Perl_Character Properties - Fatal编程技术网

Regex Perl脚本停止。错误:Can';找不到unicode属性定义ASCII

Regex Perl脚本停止。错误:Can';找不到unicode属性定义ASCII,regex,perl,character-properties,Regex,Perl,Character Properties,我继承了一些perl脚本。(我不是perl程序员) 我在下面一行看到一个错误“找不到unicode属性定义ascii” $value =~ s/[^[:\p{ascii}]]//g 这个错误会导致程序停止执行吗?因为这是程序停止前打印的最后一行 在放弃之前,同一条线路已经运行了1000多次。有什么问题吗 我倾向于认为$value的价值不是问题的根源。我说得对吗 在我看来,{ascii}似乎已从unicode定义中删除。这是可以做到的还是我完全找错了方向?在我看来ascii必须是大写的asci

我继承了一些perl脚本。(我不是perl程序员)

我在下面一行看到一个错误“找不到unicode属性定义ascii”

$value =~ s/[^[:\p{ascii}]]//g 
这个错误会导致程序停止执行吗?因为这是程序停止前打印的最后一行

在放弃之前,同一条线路已经运行了1000多次。有什么问题吗

我倾向于认为$value的价值不是问题的根源。我说得对吗


在我看来,{ascii}似乎已从unicode定义中删除。这是可以做到的还是我完全找错了方向?

在我看来
ascii
必须是大写的
ascii

$value =~ s/[^\p{ASCII}]//g 
使用\p{ascii}测试:

#> cat test.pl
#!/usr/bin/perl
my $str = q/☺ùùabvcedhkè ég"/;
$str =~ s/[^\p{ascii}]//g;
print $str,"\n";

#> perl test.pl
Can't find Unicode property definition "ascii" at test.pl line 3.
cat test.pl
#!/usr/bin/perl
my $str = q/☺ùùabvcedhkè ég"/;
$str =~ s/[^\p{ASCII}]//g;
print $str,"\n";

#> perl test.pl
abvcedhk g"
使用\p{ASCII}测试:

#> cat test.pl
#!/usr/bin/perl
my $str = q/☺ùùabvcedhkè ég"/;
$str =~ s/[^\p{ascii}]//g;
print $str,"\n";

#> perl test.pl
Can't find Unicode property definition "ascii" at test.pl line 3.
cat test.pl
#!/usr/bin/perl
my $str = q/☺ùùabvcedhkè ég"/;
$str =~ s/[^\p{ASCII}]//g;
print $str,"\n";

#> perl test.pl
abvcedhk g"

我无法解释你的代码运行一段时间后失败的原因,但是正则表达式看起来很奇怪。它匹配“除“[”、“:”或ASCII Unicode字符后跟“]”之外的任何字符。因为”['和':'本身都是ASCII Unicode字符,提及它们是多余的,这让我觉得正则表达式是不正确的。你可能转录的不正确吗?或者如果它是准确的,你知道模式应该匹配什么吗?是的,除非显式捕获错误,否则它会导致程序死亡,这不应该发生在这里没有必要。对我来说,从到
\p
/
\p
Perl表示法的转换看起来像是一个拙劣的转换。检查了三倍行,就如写入的一样。$值是从snmp::get命令中获得的。我猜它正在尝试删除所有非ascii字符。我们还有其他几乎相同的脚本,没有该lin不,从
perldoc-perluniprops
:“在解析这些结构时,Perl总是忽略{brates}中的所有大小写差异”是的,我这样做了,并且您的两个案例在我的系统(Perl v5.12.3)上都运行良好。不过,您可能已经找到了OP问题的原因。5.10在这里似乎区分大小写,但5.12和5.14不区分大小写。@ikegami:对,OP没有说他正在使用哪个版本,可能没问题。只是说如果他想继续使用小写,他需要升级到哪个版本:)(5.10不再受支持,仅供参考)