perl utf8 中文亂碼

來源:互聯網
上載者:User
[oracle@yyjk esb]$ cat a1.pluse DBI;    use HTTP::Date qw(time2iso str2time time2iso time2isoz);  use Net::SMTP;use Encode;my $dbName = 'ESBDB';    my $dbUser = 'esbdata';my $dbUserPass = 'esbdata';    my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database ";  my $sql = "select logicsystem,count(*) from  esb2_trans_log t where t.trans_date >= sysdate - 30 / 1440 and t.respcode ='500101092209' and t.logicsystem<>'TLCHAT' group by logicsystem having count(*)>0";sub sendsms{   use  LWP::UserAgent;      use LWP;     use Encode;     use LWP::Simple;     use LWP::UserAgent;     use HTTP::Cookies;     use HTTP::Headers;     use HTTP::Response;     use Encode;     use URI::Escape;     use URI::URL;     use JSON;       my $ua = LWP::UserAgent->new;    $ua->agent("Mozilla/5.0 (Windows NT 6.1; rv:30.0) Gecko/20100101 Firefox/30.0");    my $cookie_jar = HTTP::Cookies->new(       file=>'lwp_cookies.txt',       autosave=>1,       ignore_discard=>1);       $ua->cookie_jar($cookie_jar);     my $token_url= 'http://10.10.10.10:8080/tlcbspt/sendText';     my $a=shift;   my $b=shift;                  my $res = $ua->post($token_url,                  {                  'phoneNo'=>$a,                  'message'=>$b                });     print $res->content();     print "\n"; };sub sendelk{use IO::Socket::INET;$|=1;  $sock = IO::Socket::INET->new(PeerAddr => '10.10.10.10',                                   PeerPort => '9988',                                   Proto=>'tcp'                               ) or die "$!\n"; my $req=shift; my $size = $sock->send($req);  print "sent data of length $size\n"; ## notify server that request has been sent  shutdown($sock, 1);  ## receive a response of up to 1024 characters from server  my $response = "";  $sock->recv($response, 1024);  print "received response: $response\n";  $sock->close();};my $sth = $dbh->prepare($sql);       $sth->execute();    $sth->bind_columns(undef, \$system,  \$count);    $sth->execute();    while( $sth->fetch() ){        print "$system\t\t $count\n";        chomp $count;       if ($count >=0){           my $message="警示[$system]3分鐘內逾時筆數為[$count],請注意觀察!!!";           my $c=$message;           print $c."\n";           print length($c)."\n";           my $d=decode_utf8($message);           print length($d)."\n";           print $d."\n";           &sendsms('18072xx2237',"$d");           #my $e=decode_utf8($c);           &sendelk("$c");}};  $sth->finish;  my $d=decode_utf8($message);decode_utf8 解碼成unicode 字元集$message 本身是utf-8字元集[oracle@yyjk esb]$ perl a1.plSSRS 2警示[SSRS]3分鐘內逾時筆數為[2],請注意觀察!!!5929Wide character in print at a1.pl line 73.警示[SSRS]3分鐘內逾時筆數為[2],請注意觀察!!!sent data of length 59received response: CIPS 2警示[CIPS]3分鐘內逾時筆數為[2],請注意觀察!!!5929Wide character in print at a1.pl line 73.警示[CIPS]3分鐘內逾時筆數為[2],請注意觀察!!!sent data of length 59received response: 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.