• 为什么出现Wide character in print at a14.pl line 41


    [root@wx03 ~]# cat a14.pl 
    use Net::SMTP;
    use LWP::UserAgent;
    use HTTP::Cookies;
    use HTTP::Headers;
    use HTTP::Response;
    use Encode;
    use JSON;
    use File::Temp qw/tempfile/;
    use HTTP::Date qw(time2iso str2time time2iso time2isoz);
    use Data::Dumper;
    my $CurrTime = time2iso(time());
    my $dis_mainpublish='中均资本';
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    $ua->env_proxy;
    my $now          = time();
    $ua->agent('Mozilla/5.0');
    my $cookie_jar = HTTP::Cookies->new(
    
        file           => 'lwp_cookies.txt',
        autosave       => 1,
        ignore_discard => 1
    );
    $ua->cookie_jar($cookie_jar);
    my $response = $ua->get("https://www.zjcap.cn/web/noauth?method=%2Fproduct%2Flist&duration=&entryUnit=&productType=1&status=&yield=&productName=&pageNum=1&pageSize=6&_=1468156037154");
    
    
    if ($response->is_success) {
      $r = $response->decoded_content;   
      print "
    ";
      }
      else 
      {
      die $response->status_line;
      };
    #my $r=encode_utf8($r);
    my $hash = decode_json ( $r );
    print "11111111111111111111
    ";
    #print Dumper($hash);
    print "产品列表
    ";
    print $hash->{data}->{dataList}->[0]->{name};
    
    
    [root@wx03 ~]# perl a14.pl 
    
    11111111111111111111
    产品列表
    Wide character in print at a14.pl line 41.
    中均-欧洲杯18号(葡萄牙加时/点球夺冠)[root@wx03 ~]# 
    
    
    为什么出现Wide character in print at a14.pl line 41. 呢/
    
    因为my $hash = decode_json ( $r );
    
    $r 没有转换成utf-8 binary string
    
    
    /****************************************************
    
    [root@wx03 ~]# cat a14.pl 
    use Net::SMTP;
    use LWP::UserAgent;
    use HTTP::Cookies;
    use HTTP::Headers;
    use HTTP::Response;
    use Encode;
    use JSON;
    use File::Temp qw/tempfile/;
    use HTTP::Date qw(time2iso str2time time2iso time2isoz);
    use Data::Dumper;
    my $CurrTime = time2iso(time());
    my $dis_mainpublish='中均资本';
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    $ua->env_proxy;
    my $now          = time();
    $ua->agent('Mozilla/5.0');
    my $cookie_jar = HTTP::Cookies->new(
    
        file           => 'lwp_cookies.txt',
        autosave       => 1,
        ignore_discard => 1
    );
    $ua->cookie_jar($cookie_jar);
    my $response = $ua->get("https://www.zjcap.cn/web/noauth?method=%2Fproduct%2Flist&duration=&entryUnit=&productType=1&status=&yield=&productName=&pageNum=1&pageSize=6&_=1468156037154");
    
    
    if ($response->is_success) {
      $r = $response->decoded_content;   
      print "
    ";
      }
      else 
      {
      die $response->status_line;
      };
    my $r=encode_utf8($r);
    my $hash = decode_json ( $r );
    print "11111111111111111111
    ";
    #print Dumper($hash);
    print "产品列表
    ";
    print $hash->{data}->{dataList}->[0]->{name};
    [root@wx03 ~]# perl a14.pl 
    
    11111111111111111111
    产品列表
    中均-欧洲杯18号(葡萄牙加时/点球夺冠)[root@wx03 ~]# 
    

  • 相关阅读:
    设计模式之单一职责原则
    设计模式之策略模式
    设计模式之简单工厂模式
    基于 Docker 的微服务架构实践
    深入理解Redis内存模型
    Spring核心——设计模式与IoC
    P9架构师讲解从单机至亿级流量大型网站系统架构的演进过程
    大型分布式网站架构:缓存在分布式系统中的应用
    阿里架构师的日志:带你快速理解微服务架构;理解微服务架构的核心
    Spring核心——Bean的定义与控制
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350553.html
Copyright © 2020-2023  润新知