开发者

Remove wide characters, Perl

I am trying to send a String via a socket using a perl program. I am getting an error saying that the text contains a wide character, and the socket can't deal with that. Is there a way to either:

A: Turn on wide characters through the socket

or

B: Remove all 开发者_开发百科wide characters from a string?


It means you're trying to send text over a handle, yet handles can only communicate bytes. You need to serialise the text into bytes. Specifically, you want to encode the text. You can use Encode's encode function

print $sock encode('some_encoding', $text);

or you can instruct the socket to do it for you

binmode $sock, ':encoding(some_encoding)';  # once
print $sock $text;

Replace some_encoding with the encoding expected by the other end of the socket (e.g. UTF-8).


PerlIO and binmode might help you solve your problems

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜