带有utf8字符的Perl regexp
我有两个文件:带有utf8字符的Perl regexp,perl,Perl,我有两个文件:t.pl和t: $ file t.pl t t.pl: UTF-8 Unicode text t: UTF-8 Unicode text $ cat t 日本 t、 pl有三个版本: 案例1 use strict; use warnings; use utf8; $_='日本'; if(/日/){ print "match!\n"; } 和perl t.ploutpusmatch 案例2 use strict; use warnings; use utf8;
t.pl
和t
:
$ file t.pl t
t.pl: UTF-8 Unicode text
t: UTF-8 Unicode text
$ cat t
日本
t、 pl有三个版本:
案例1
use strict;
use warnings;
use utf8;
$_='日本';
if(/日/){
print "match!\n";
}
和perl t.pl
outpusmatch代码>
案例2
use strict;
use warnings;
use utf8;
while(<DATA>){
chomp;
if(/日/){
print "match!\n";
}
}
__DATA__
日本
perl t.pl t
不显示匹配代码>
那么案例3有什么问题呢?您必须为输入设置编码,使用utf8
不适合您。插入
use open IN => ":utf8";
在循环之前。有关详细信息,请参阅。可能需要更通用的使用open':std',':utf8'代码>
use open IN => ":utf8";