utf8字节

<pre name="code" class="html">[root@wx03 0724]# perl a1.pl 
112
[root@wx03 0724]# perl a1.pl 
dawe^H^H微信adda
success
[root@wx03 0724]# perl a1.pl 
22微信3131 
success
[root@wx03 0724]# 

[root@wx03 0724]# cat a1.pl 
my $a=<STDIN>;
my $b='微信';
if ($a =~/$b/){print "success\n";};



[root@wx03 0724]# perl a1.pl 
22微信3131
[root@wx03 0724]# cat a1.pl 
use Mojolicious::Lite;
my $a=<STDIN>;
my $b='微信';
if ($a =~/$b/){print "success\n";};

此时匹配不上了:



因为开启了utf8;

[root@wx03 0724]# perl a1.pl 
22微信3131
success
[root@wx03 0724]# cat a1.pl 
use Mojolicious::Lite;
use Encode;
my $a=<STDIN>;
my $b=encode_utf8('微信');
if ($a =~/$b/){print "success\n";};


继续测试;
[root@wx03 0724]# perl a1.pl 
"my" variable $a masks earlier declaration in same scope at a1.pl line 4, <DATA> line 2125.
23微信2231
success

[root@wx03 0724]# cat a1.pl 
use Mojolicious::Lite;
use Encode;
my $a=<STDIN>;
my $a=decode_utf8("$a");
my $b='微信';
if ($a =~/$b/){print "success\n";};




[root@wx03 0724]# perl a1.pl 
"my" variable $a masks earlier declaration in same scope at a1.pl line 5, <DATA> line 2125.
23微信2231
$a is 23微信2231

Wide character in print at a1.pl line 6, <STDIN> line 1.
$a is 23微信2231

success

[root@wx03 0724]# cat a1.pl 
use Mojolicious::Lite;
use Encode;
my $a=<STDIN>;
print "\$a is $a\n";
my $a=decode_utf8("$a");
print "\$a is $a\n";
my $b='微信';
if ($a =~/$b/){print "success\n";};



/******************
[root@wx03 0724]# perl a2.pl 
23微信2231
$b is 微信
success

[root@wx03 0724]# cat a2.pl 
use Encode;
use Mojolicious::Lite;
my $a=<STDIN>;
my $b=encode_utf8('微信');
print "\$b is $b\n";
if ($a =~/$b/){print "success\n";};



[root@wx03 0724]# perl a2.pl 
23微信2231
$b is 微信

[root@wx03 0724]# cat a2.pl 
use Encode;
my $a=<STDIN>;
my $b=encode_utf8('微信');
print "\$b is $b\n";
if ($a =~/$b/){print "success\n";};
[root@wx03 0724]# 


 
 
 

转载于:https://www.cnblogs.com/zhaoyangjian724/p/6199513.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值