Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Perl DBI can't display Chinese text?

by graff (Chancellor)
on Oct 13, 2013 at 21:45 UTC ( #1058105=note: print w/replies, xml ) Need Help??

in reply to Perl DBI can't display Chinese text?

Do you have some method other than Perl for inspecting the contents of the database? It's important to know for sure that the database contains "correct" data in the first place.

If that's true, the next thing is to make sure what character encoding is being used by the database server to store (or return) the data.

If the database stores/returns data in UTF-8 encoding, the next thing is to do just one of the following (whichever one is easiest or makes the most sense):

1. Figure out how to configure your perl DBI connection to the database, so that perl will know that it's getting UTF-8 data in response to queries. OR

2. Connect using the "easiest" (default) method, and use Encode; process each string you get from a query like this:

my $usable_string = decode( 'utf8', $string_from_database );
The latter approach would also work if you find out that the database server returns strings using some other encoding (e.g. "gb2312" or whatever) - just use that other encoding in place of "utf8" in the decode() call, and that will turn the database string into perl-internal (usable) utf8.

If you have trouble, you'll need to show us (1) an example of data you expect to get back (because you've seen this data using some other tool to query the database), (2) the perl code you used to try getting the string, and (3) what you actually got from your perl script.

As indicated in a previous reply above, it may also be important to ensure that you are using a terminal or other display method that you are sure is able to "do the right thing" with the text in question.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1058105]
[Eily]: s/\K\bis\b/h/
[Tux]: you left the space in
[Tux]: and that \K is not required
[Tanktalus]: 11.31 is already 10 years old... you still need to support versions older than that? My condolences :)
[Eily]: meh, got confused. s/(?=\bis\b)/h/ will work better :)
[Eily]: \K keeps the thing on the left, not the right (IE, it's like look behind, not look ahead)
[Tux]: and 11.31 is still the last stable. We're moving all our customers to Linux (openSUSE and CentOS), but that takes a loooooooooooooooon g time
[LanX]: ehm ... I woke up my *boobs* ?
LanX where is the camera?
Tux => $HOME

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2017-09-20 16:38 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (237 votes). Check out past polls.