Remove wide characters, perl

I am trying to send String through a socket using the perl program. I get a message that the text contains a wide character, and the socket cannot handle it. Is there any way:

A: enable wide characters via socket

or

B: delete all wide characters from a string?

+4
source share
2 answers

This means that you are trying to send text by descriptor, but descriptors can only transmit bytes. You need to serialize the text into bytes. In particular, you want to encode text. You can use Encode encode function

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

or you can instruct the socket to do this 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 ).

+10
source

PerlIO and binmode can help you solve your problems

0
source

All Articles