in reply to Encoding problem in perl
Your test isn't runnable, so I had to adapt it a bit
#!/usr/bin/perl use strict; use warnings; use Encode qw( encode from_to ); print("Content-Type: text/html; charset=utf-8\n\n"); my $name = encode('utf-16le', "\x{65E5}\x{672C}\x{8A9E}"); eval { from_to($name, 'utf-16le', 'utf-8', Encode::FB_CROAK); 1 } or print("coaked\n"); print $name;
It works fine. It displays "Japanese (language)" in Japanese.
From the prompt, I get:
$ test.cgi | od -c 0000000 C o n t e n t - T y p e : t +e 0000020 x t / h t m l ; c h a r s e +t 0000040 = u t f - 8 \n \n 346 227 245 346 234 254 350 25 +2 0000060 236 0000061
Find what differs, and you'll find which bad assumption you made.
By the way, the following is a better model:
#!/usr/bin/perl use strict; use warnings; use Encode qw( encode decode ); binmode(STDOUT, ':encoding(utf-8)'); print("Content-Type: text/html; charset=utf-8\n\n"); # Input my $name = encode('utf-16le', "\x{65E5}\x{672C}\x{8A9E}"); eval { $name = decode('utf-16le', $name, Encode::FB_CROAK); 1 } or print("coaked\n"); # Process # ... # Output print $name;
|
|---|