Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Handling Traditional Chinese Characters

by Polyglot (Pilgrim)
on Jun 18, 2009 at 23:48 UTC ( #772872=note: print w/replies, xml ) Need Help??

in reply to Handling Traditional Chinese Characters

From experience I can tell you that not every CPAN module is capable of properly handling the Asian languages, especially Chinese, Japanese, and Korean (CJK). I would guess, in fact, that the majority of them are not compatible with these languages. I have frequently had to write my own code to deal with them because of this.

Here are some tips on ways to deal with everything in UTF8:

use Encode; use Encode qw(encode decode); binmode STDOUT, ':utf8'; print "Content-type: text/html; charset=utf-8\n\n"; open SOURCE, '<:encoding(utf8)',$sourcefile or die "Cannot open source! $!\n"; open (TARGET, ">:encoding(utf8)", "$targetfile") or die "Cannot open target file! $!\n"; print TARGET <<HTML; <html lang="utf8"> <head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf8"> ... <form name="myform" method="POST" accept-encoding="UTF-8" accept-chars +et="utf-8" action="$thisprogram"> ... HTML foreach $line (@source) { $line = decode("utf-8", $line);

Note that you may not need to do all of these at once. For example, if you already read the file in as UTF8, there is no need to decode each line of the file as UTF8 again. However, redundancy should have no side effects other than adding a little more bulk to your code.


~ Polyglot ~

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://772872]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-02-21 17:46 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (285 votes). Check out past polls.