zoukankan      html  css  js  c++  java
  • perl mojo 处理文本

    1.关闭utf8
    
    centos6.5:/root#cat t2.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!  
                           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;  
                        print "length$a3--------------
    ";
                        print length($a3);
                        print "
    ";
                        print "--------------
    ";
                       
                        my $a5="测试更健康";
                        print "length$a5--------------
    ";
                        print length($a5);
                        print "
    ";
                        print "--------------
    ";
    
              $c->render(text => "$a5" );  
    };  
    };
    };                     
      
      
      app->start;
    centos6.5:/root#cat 11.out 
    2016-03-09 09:35:12,380 INFO com.zjzc.thirdparty.sms.SMSUtils - Send message:验证to phoneNo:18072722237 succeed! 
    centos6.5:/root#
    
    
    
    [root@yun-bak ~]# curl http://192.168.11.185:3000/admin/api/menu
    æµè¯æ´å¥åº·[root@yun-bak ~]# 
    
    此时curl 返回乱码
    
    
    centos6.5:/root#cat t2.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!  
                           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;  
                        print "length$a3--------------
    ";
                        print length($a3);
                        print "
    ";
                        print "--------------
    ";
                       
                        my $a5=decode_utf8("测试更健康");
                        print "length$a5--------------
    ";
                        print length($a5);
                        print "
    ";
                        print "--------------
    ";
                           
              $c->render(text => "$a5" );  
    };  
    };
    };                     
      
      
      app->start;
    centos6.5:/root#morbo t2.pl 
    Server available at http://127.0.0.1:3000
    [Sun Mar 12 16:10:01 2017] [debug] GET "/admin/api/menu"
    [Sun Mar 12 16:10:01 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 验证
    $a4 is to phoneNo:18072722237
    length$a3--------------
    6
    --------------
    length$a5--------------
    5
    --------------
    [Sun Mar 12 16:10:01 2017] [debug] 200 OK (0.00105s, 952.381/s)
    readline() on closed filehandle LOG1 at /root/t2.pl line 15.
    
    
    [root@yun-bak ~]# curl http://192.168.11.185:3000/admin/api/menu
    测试更健康[root@yun-bak ~]# 
    
    
    
    1.开启utf8
    
    centos6.5:/root#cat t2.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!  
                           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;  
                        print "length$a3--------------
    ";
                        print length($a3);
                        print "
    ";
                        print "--------------
    ";
                       
                        my $a5="测试更健康";
                        print "length$a5--------------
    ";
                        print length($a5);
                        print "
    ";
                        print "--------------
    ";
                           
              $c->render(text => "$a5" );  
    };  
    };
    };                     
      
      
      app->start;
    centos6.5:/root#morbo t2.pl 
    Server available at http://127.0.0.1:3000
    [Sun Mar 12 16:12:06 2017] [debug] GET "/admin/api/menu"
    [Sun Mar 12 16:12:06 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 验证
    $a4 is to phoneNo:18072722237
    length$a3--------------
    6
    --------------
    length$a5--------------
    5
    --------------
    [Sun Mar 12 16:12:06 2017] [debug] 200 OK (0.001204s, 830.565/s)
    readline() on closed filehandle LOG1 at /root/t2.pl line 14.
    
    
    [root@yun-bak ~]# curl http://192.168.11.185:3000/admin/api/menu
    测试更健康[root@yun-bak ~]# 
    

  • 相关阅读:
    即时通讯之环信视频语音实时通话与单聊和群聊实现
    检测.net framework 版本
    Abp(.NetCore)开发与发布过程3-部署Ubuntu站点
    Abp(.NetCore)开发与发布过程2
    Abp(.NetCore)开发与发布过程
    Redis实战与 Session缓存
    Redis 安装与初体验
    [转]gluPerspective函数
    [转]gluLookAt 函数详解
    [转]unity3D游戏开发之GUI
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349823.html
Copyright © 2011-2022 走看看