Subject: | Wide character in print.ERROR at Net/Stomp.pm 21 line! |
Send Chinese Code will waring this:
success send keyword Heartbreaker!
Wide character in print at D:/Perl/lib/IO/Handle.pm line 406, <KFILE>
line 4.
success send keyword 御用闲人!
Wide character in print at D:/Perl/lib/IO/Handle.pm line 406, <KFILE>
line 5.
success send keyword 夜隹大队!
Wide character in print at D:/Perl/lib/IO/Handle.pm line 406, <KFILE>
line 6.
success send keyword 午夜郎君!
Wide character in print at D:/Perl/lib/IO/Handle.pm line 406, <KFILE>
line 7.
success send keyword 美国派!
Wide character in print at D:/Perl/lib/IO/Handle.pm line 406, <KFILE>
line 8.
Fixed:
Edit Net/Stomp.pm
package Net::Stomp;
use strict;
use warnings;
use IO::Socket::INET;
use IO::Select;
use Net::Stomp::Frame;
use base 'Class::Accessor::Fast';
__PACKAGE__->mk_accessors(qw(hostname port select socket));
our $VERSION = '0.34';
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
my $socket = IO::Socket::INET->new(
PeerAddr => $self->hostname,
PeerPort => $self->port,
Proto => 'tcp'
);
die "Error connecting to " . $self->hostname . ':' . $self->port .
": $!"
unless $socket;
binmode($socket); à binmode($socket, ':encoding(utf8)');
$self->socket($socket);
my $select = IO::Select->new();
$select->add($socket);
$self->select($select);
return $self;
}
Code:
#!/usr/bin/perl -w
use strict;
use warnings;
use Net::Stomp::Receipt;
use Encode;
binmode(STDIN, ':encoding(utf8)');
binmode(STDERR, ':encoding(utf8)');
binmode(STDOUT, ':encoding(gbk)');
my $stomp = Net::Stomp::Receipt->new({hostname => '192.168.0.46',port
=> '61613',PERSISTENT => 1,});
print $stomp."\n";
$stomp->connect({login=> 'sa',passcode => '223238'});
my $mq = "keywordspider.keyword.queue";
open(KFILE,"keyword");
while(<KFILE>){
chomp();
my $keyword = decode("utf8",$_);
$stomp->send_safe({destination =>
'/queue/editspider.keyword.queue',body =>
'{"keyword":"'.$keyword.'","isAlbum":"true","isVideo":"false","extension":""}'})
or die "Couldn't send the message!";
print "success send keyword $keyword!\n";
}