zoukankan      html  css  js  c++  java
  • perl encode_utf8必须用在utf8环境

    [root@wx03 mojo]# cat test.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;
              print "测试更健康
    ";
             open (LOG1 ,"<",'/data01/applog_backup/zj-api01-catalina.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 ( ($phone) and ($_ =~/$phone/) and ($_ =~/SMSUtils/) ){$str=$_;
    					
    					my $x='验证';
                                            print "$x is $x
    ";
    			 		my $d=encode_utf8('验证');
                                            print "$d is $d
    ";
                                            
    					print "1-------$str is $str
    ";
    					next if ($str !~ /$d/);
    					print "2--------$str is $str
    ";
    					#push (@arr1 ,decode_utf8($str));
    					push (@arr1 ,$str);
    					}};
    					
    					close LOG1;
              $c->render(json =>  @arr1 );
    };
    				   
    
    
      app->start;
      
      
      
      
      
      
      [root@wx03 mojo]# morbo test.pl 
    Server available at http://127.0.0.1:3000
    Wide character in print at /root/mojo/test.pl line 10.
    测试更健康
    Wide character in print at /root/mojo/test.pl line 19, <LOG1> line 1.
    $x is 验证
    $d is 验证
    1-------$str is 2016-04-22 11:02:01,259 INFO com.zjzc.thirdparty.sms.SMSUtils - Send message:您的验证码为813231,本验证码30分钟内有效。 to phoneNo:18072722237 succeed!
    
    2--------$str is 2016-04-22 11:02:01,259 INFO com.zjzc.thirdparty.sms.SMSUtils - Send message:您的验证码为813231,本验证码30分钟内有效。 to phoneNo:18072722237 succeed!
    
    Wide character in print at /root/mojo/test.pl line 19, <LOG1> line 3.
    $x is 验证
    $d is 验证
    1-------$str is 2016-04-22 11:02:01,259 INFO com.zjzc.thirdparty.sms.SMSUtils - Send message:您的813231,本30分钟内有效。 to phoneNo:18072722237 succeed!
    
    Wide character in print at /root/mojo/test.pl line 19, <LOG1> line 4.
    $x is 验证
    $d is 验证
    1-------$str is 2016-04-22 11:02:01,259 INFO com.zjzc.thirdparty.sms.SMSUtils - Send message:您的813231,本30分钟内有效。 to phoneNo:18072722237 succeed!
    
    
    此时$d和$x都正常显示
    
    
    [root@wx03 mojo]# cat c1.pl 
    use Encode;
    	my $x='验证';
            print "$x is $x
    ";
            my $d=encode_utf8('验证');
            print "$d is $d
    ";
    [root@wx03 mojo]# perl c1.pl 
    $x is 验证
    $d is 验证 
    
    
    说明encode_utf8 必须用在utf8编码环境
    

  • 相关阅读:
    python-函数(下):递归、高阶函数
    Spring Hystrix 原理与使用详解
    Jmeter 添加kafka支持
    dnspod-sr 高性能DNS 服务器软件
    Jupyter精选资源合集
    spring 跨域CORS Filter
    TensorFlow 基础准备指导
    TortoiseGit SSH-key 免用户名密码验证
    node.js、npm 升级操作详解
    Maven -DskipTests和-Dmaven.test.skip=true的区别
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6199645.html
Copyright © 2011-2022 走看看