dcunningham has asked for the wisdom of the Perl Monks concerning the following question:
Esteemed monks, I have a problem with encoding of an emoji in perl. The string "Test 😀" is read from a MySQL database table which has encoding latin1. Obviously that's not a UTF-8 character set, but my console seems smart enough to detect the intended output, as a plain "select * from table" on the "mysql" client displays the "grinning face" emoji correctly.
Then my perl (version 5.26) program logs the text to a log file, and again running "tail -f" on the log file displays the emoji in the text correctly. I also log the bytes using sprintf( "%vX", $text) and it prints "54.65.73.74.20.F0.9F.98.80". So the bytes for the emoji are there, in "F0.9F.98.80".
Then the text is JSON encoded (using the JSON library), and sent using $conn->send_utf8() to a websocket client using Net::WebSocket::Server, however the websocket client (running in a web browser) receives "Test ð". I've tried encode( 'UTF-8', $text ) which did not fix the problem.
The whole subject of character encoding is not an easy one, and mixing MySQL with Perl with websockets (with JSON for good measure) has made it tricky to tell where the problem is.
Can anyone help find why the websocket client doesn't receive the emoji correctly please?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Encoding of emoji character
by soonix (Chancellor) on Jun 20, 2022 at 06:25 UTC | |
|
Re: Encoding of emoji character
by Anonymous Monk on Jun 20, 2022 at 06:05 UTC | |
by dcunningham (Sexton) on Jun 20, 2022 at 09:17 UTC | |
by soonix (Chancellor) on Jun 20, 2022 at 11:58 UTC | |
by choroba (Cardinal) on Jun 20, 2022 at 13:04 UTC | |
by dcunningham (Sexton) on Jun 20, 2022 at 21:27 UTC | |
by soonix (Chancellor) on Jun 21, 2022 at 18:47 UTC | |
| |
by Anonymous Monk on Jun 21, 2022 at 06:09 UTC | |
| |
by NERDVANA (Priest) on Jun 22, 2022 at 18:53 UTC | |
by Anonymous Monk on Jun 20, 2022 at 09:50 UTC | |
by dcunningham (Sexton) on Jun 20, 2022 at 21:32 UTC |