Re: unicode issue in Perl CGI

[email protected] (Darren Duncan)
Newsgroups perl.unicode
Message-ID <p06230901c0d483e255de@[192.168.1.101]>
At 6:03 PM +0530 7/7/06, uttam hoode wrote:
>hi friends,
>     i have  a CGI form which recieves name, address etc and stores 
>it in Oracle database.
>For english language it is working fine. but when i try to store 
>some arabic data it is
>displayed as '??????' (in browser, when queried) .
>
>also i want to know how to compare two unicode values in Perl.
>
>  eg  $city eq "xxxxxxxx"   where x  is a unicode data in hebrew
>
>Regards,
>uttam

I was working through solving some similar problems yesterday, so may 
be able to help you.  If you do these things consistently, it should 
help you:

1. Assuming you have a Unicode-saavy text editor and are using Perl 
5.8.1 or later, put "use utf8;" at the top of all your Perl files. 
When you do that, you can put literal Unicode characters in your 
code, so you can type in the "xxxx" literally.

2. If you are running in CGI mode of faux CGI mode like 
Apache::Registry, do a "binmode( STDOUT, ':utf8' )" when your program 
starts up, and also include a -charset => 'UTF-8' argument in your 
CGI header() call, so that your output is declared in and actually in 
UTF-8, so you can see output correctly.

3. Third, since CGI.pm seems to not be Unicode aware and passes data 
through as bytes, try doing this on what you get from param():

     if (!Encode::is_utf8( $param_val )) {
         $param_val = Encode::decode_utf8( $param_val );
     }

4. As I don't use Oracle now, I don't know the details, but you may 
separately have to configure the Oracle connection charset and/or 
filter its input and output to be Unicode.  I know I had to for 
MySQL.  Make sure your tables are defined as Unicode.

-- Darren Duncan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.