• perl mojo use utf8 和no utf8


    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;  
              print "测试更健康
    ";  
             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=$_;  
                    #   my $d=encode_utf8('验证');  
                        print "1111111111111111
    "; 
                        }};  
                          
                        close LOG1;  
              $c->render(text =>  "测试更健康" );  
    };  
                         
      
      
      app->start;
    centos6.5:/root#morbo t1.pl 
    Server available at http://127.0.0.1:3000
    [Thu Mar  9 13:55:15 2017] [debug] GET "/admin/api/menu"
    [Thu Mar  9 13:55:15 2017] [debug] Routing to a callback
    Wide character in print at /root/t1.pl line 11.
    测试更健康
    [Thu Mar  9 13:55:15 2017] [debug] 200 OK (0.000833s, 1200.480/s)
    
    
    
    此时没有输出 111111111111 ,说明没有匹配到,
      
      
      
      
    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;  
              print "测试更健康
    ";  
             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=$_;  
                        print "1111111111111111
    "; 
                        }};  
                          
                        close LOG1;  
              $c->render(text =>  "测试更健康" );  
    };  
                         
      
      
      app->start;
    centos6.5:/root#morbo t1.pl 
    Server available at http://127.0.0.1:3000
    [Thu Mar  9 13:56:16 2017] [debug] GET "/admin/api/menu"
    [Thu Mar  9 13:56:16 2017] [debug] Routing to a callback
    Wide character in print at /root/t1.pl line 11.
    测试更健康
    1111111111111111
    [Thu Mar  9 13:56:16 2017] [debug] 200 OK (0.000998s, 1002.004/s)
    
    
    打开utf8 的情况下, 如果需要匹配中文  需要  encode_utf8('验证'); 
    
    
    
    
    /********************************************************************8/
    
    
    关闭utf 8情况:
    
    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;  
              print "测试更健康
    ";  
             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=$_;  
                        print "1111111111111111
    "; 
                        }};  
                          
                        close LOG1;  
              $c->render(text =>  "测试更健康" );  
    };  
                         
      
      
      app->start;
    centos6.5:/root#morbo t1.pl 
    Server available at http://127.0.0.1:3000
    [Thu Mar  9 13:58:15 2017] [debug] GET "/admin/api/menu"
    [Thu Mar  9 13:58:15 2017] [debug] Routing to a callback
    测试更健康
    1111111111111111
    [Thu Mar  9 13:58:15 2017] [debug] 200 OK (0.000852s, 1173.709/s)
      
     此时   my $d='验证'; 可以匹配到
     
     
     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;  
              print "测试更健康
    ";  
             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=$_;  
                        print "1111111111111111
    "; 
                        }};  
                          
                        close LOG1;  
              $c->render(text =>  "测试更健康" );  
    };  
                         
      
      
      app->start;
    centos6.5:/root#morbo t1.pl 
    Server available at http://127.0.0.1:3000
    [Thu Mar  9 13:59:40 2017] [debug] GET "/admin/api/menu"
    [Thu Mar  9 13:59:40 2017] [debug] Routing to a callback
    测试更健康
    [Thu Mar  9 13:59:40 2017] [debug] 200 OK (0.00107s, 934.579/s)
    
    
    此时 关闭utf8 不需要 $d=encode_utf8('验证');
      

  • 相关阅读:
    hdu2653 Waiting ten thousand years for Love
    Request
    freetextbox 使用方法+下载
    格式化字符串 GridView DataFormatString
    GridView 中的button LinkButton 事件 CommandName
    Response 缓存
    Windows 7下VS2008升级
    ASP.NET中备份SQL Server数据库的方法
    asp.net和c#实现定时备份数据库(SQL Server2000)
    asp.net 中保存 数据库几种对象
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349837.html
Copyright © 2020-2023  润新知