centos6.5:/root#cat t1.pl
use Mojolicious::Lite;
use JSON qw/encode_json decode_json/;
use Encode;
no strict;
no utf8;
use JSON;
use Data::Dumper;
# /foo?user=sri
get '/admin/api/menu' => sub {
my $c = shift;
open (LOG1 ,"<",'11.out') or die $!;
while (<LOG1>) {
my $phone='18072722237';
#2016-03-09 09:35:12,380 INFO com.zjzc.thirdparty.sms.SMSUtils - Send message:您的验证码为132435,本验证码5分钟内有效。 to phoneNo:18072722237 succeed!
my $d='验证';
#my $d='验证';
if ( ($phone) and ($_ =~/$phone/) and ($_ =~/$d/) ){$str=$_;
if ($_ =~ /([0-9]{4}-[0-9]{1,2}-[0-9]{2}s+[0-9]{2}:[0-9]{2}:[0-9]{2}.*?)s+(.*?Send message:)s*(.*?)(tos+phoneNo:s*[0-9]{11}).*/){
$a1=$1;
$a2=$2;
$a3=$3;
$a4=$4;
print "$a1 is $a1
";
print "$a2 is $a2
";
print "$a3 is $a3
";
print "$a4 is $a4
";
}};
close LOG1;
my $a=decode_utf8("测试更健康");
print "--------------
";
print length($a);
print "--------------
";
$c->render(text => "$a" );
};
};
app->start;
centos6.5:/root#morbo t1.pl
Server available at http://127.0.0.1:3000
[Sat Mar 11 13:48:49 2017] [debug] GET "/admin/api/menu"
[Sat Mar 11 13:48:49 2017] [debug] Routing to a callback
$a1 is 2016-03-09 09:35:12,380
$a2 is INFO com.zjzc.thirdparty.sms.SMSUtils - Send message:
$a3 is 您的验证码为132435,本验证码5分钟内有效。
$a4 is to phoneNo:18072722237
--------------
5--------------
[Sat Mar 11 13:48:49 2017] [debug] 200 OK (0.0011s, 909.091/s)
readline() on closed filehandle LOG1 at /root/t1.pl line
[root@yun-bak ~]# curl http://192.168.11.185:3000/admin/api/menu
测试更健康[root@yun-bak ~]#
my $a=decode_utf8("测试更健康");
这里需要decode_utf8 转换成utf8 字符
[oracle@oadb utf-8]$ cat a1.pl
use Encode;
my $str="测试更健康";
print length($str);
print "
";
print $str."
";
[oracle@oadb utf-8]$ perl a1.pl
15
测试更健康