7

次のコード:

#!/usr/bin/env perl
use utf8;
use strict;
use warnings;
use 5.012; # implicitly turn on feature unicode_strings
my $test = "some string";
$test =~ m/.+\x{2013}/x;

収量:

test.pl 9 行$test目のパターンマッチで初期化されていない値が使用されています。(m//)

これは、 内の任意の 2 バイト文字で発生するよう\x{}です。次の正規表現は正常に機能します。

/a+\x{2013}/
/.*\x{2013}/
/.+\x{20}/

また、エラーは で解消されますがuse bytes、そのプラグマの使用はお勧めできません。何が起きてる?

4

2 に答える 2

5

これはバグであり、コミット 7e0d5ad7c9cdb21b681e611b888acd41d34c4d05 および c72077c4fff72b66cdde1621c62fb4fd383ce093 によって修正されました。この修正は 5.17.5 で利用可能になるはずです

于 2012-10-17T04:19:25.163 に答える
3

この質問をするのは珍しいことです。昨日報告し​​たばかりのバグに関連しているようです

https://rt.perl.org/rt3/Ticket/Display.html?id=114808

ここで、このコードは"Use of uninitialized value $_ in split ..."警告も生成splitし、予期せず空のリストを返します。

use warnings;
binmode *STDOUT, ":encoding(UTF-8)";
my $pattern = "\x{abc}\x{def}ghi";
for ( "\x{444}", "norm\x{a0}l", "\x{445}", "ab\x{ccc}de\x{fff}gh" ) {
  print "--------------------\ntext is $_, pattern is /$pattern/\n";

  # expect  split  to return  ($_) , but when $pattern and $_ both
  # have wide chars, it returns  ()
  print 'split output is [', split /$pattern/, $_;

  print "]\n";
}
于 2012-09-10T20:30:14.777 に答える