2

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

"can't find unicode property definition ascii"在下一行看到一个错误

$value =~ s/[^[:\p{ascii}]]//g 

这个错误会导致程序执行停止吗?因为它是程序停止前打印的最后一行。

在它放弃之前,同一条生产线已经运行了 1000 多次。问题可能是什么?

我倾向于$value 的值不是导致问题的原因。我对吗?

在我看来,好像 {ascii} 已从 unicode 定义中删除。可以这样做还是我完全吠错了树?

4

1 回答 1

2

在我看来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.

使用 \p{ASCII} 进行测试:

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

#> perl test.pl
abvcedhk g"
于 2012-01-19T13:21:15.220 回答