perl mojo 编码

来源:互联网 发布:类似sketch windows 编辑:程序博客网 时间:2024/06/15 02:35
mojo 默认开启utf8;centos6.5:/root#cat t1.pl use Mojolicious::Lite;  use JSON qw/encode_json decode_json/;    use Encode;  no strict;  use JSON;   use Data::Dumper;  no utf8;# /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*(.*?)(to\s+phoneNo:\s*[0-9]{11}).*/){                       $a1=$1;                $a2=$2;                 $a3=$3;                  $a4=$4;                        print "\$a1 is $a1\n";                        print "\$a2 is $a2\n";                        print "\$a3 is $a3\n";                        print "\$a4 is $a4\n";                    }};                                            close LOG1;                      my $a=decode_utf8("测试更健康");          $c->render(text =>  "$a" );  };  };                           app->start;      centos6.5:/root#morbo t1.pl Server available at http://127.0.0.1:3000[Thu Mar  9 20:57:25 2017] [debug] GET "/admin/api/menu"[Thu Mar  9 20:57:25 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[Thu Mar  9 20:57:25 2017] [debug] 200 OK (0.000969s, 1031.992/s)readline() on closed filehandle LOG1 at /root/t1.pl line 31.  centos6.5:/root#curl http://127.0.0.1:3000/admin/api/menu测试更健康centos6.5:/root#curl http://127.0.0.1:3000/admin/api/menu测试更健康centos6.5:/root#开启utf8;centos6.5:/root#vim t1.pl use Mojolicious::Lite;use JSON qw/encode_json decode_json/;use Encode;no strict;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*(.*?)(to\s+phoneNo:\s*[0-9]{11}).*/){                        $a1=$1;                        $a2=$2;                        $a3=$3;                        $a4=$4;                        print "\$a1 is $a1\n";                        print "\$a2 is $a2\n";                        print "\$a3 is $a3\n";                        print "\$a4 is $a4\n";                    }};                    close LOG1;                    my $a="测试更健康";          $c->render(text =>  "$a" );};};  app->start;               centos6.5:/root#morbo t1.pl Server available at http://127.0.0.1:3000[Thu Mar  9 20:58:47 2017] [debug] GET "/admin/api/menu"[Thu Mar  9 20:58:47 2017] [debug] Routing to a callback[Thu Mar  9 20:58:47 2017] [debug] 200 OK (0.000981s, 1019.368/s)readline() on closed filehandle LOG1 at /root/t1.pl line 30.此时匹配不到/******************centos6.5:/root#cat t1.pl use Mojolicious::Lite;  use JSON qw/encode_json decode_json/;    use Encode;  no strict;  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=encode_utf8('验证');                     #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*(.*?)(to\s+phoneNo:\s*[0-9]{11}).*/){                       $a1=$1;                $a2=$2;                 $a3=$3;                  $a4=$4;                        print "\$a1 is $a1\n";                        print "\$a2 is $a2\n";                        print "\$a3 is $a3\n";                        print "\$a4 is $a4\n";                    }};                                            close LOG1;                      my $a="测试更健康";          $c->render(text =>  "$a" );  };  };                           app->start;    此时可以匹配

0 0
原创粉丝点击