tags:

views:

204

answers:

1

Hi Guys ,

In my script I need to "qw" some chinese character into a string . when I run the script , perl conplains that there is unrecognized character in the script . Although I know it must related to encode related stuff , but I don't know how to solve it . so turn to you for help .

thanks in advance .

+9  A: 

Embedding literal strings in Perl source code is easy. Use the utf8 pragma. (Do not use the encoding pragma, it is highly problematic.)

use utf8;
my $perl_string = '你好,张HY';

Your text editor must save this file as UTF-8, too.

Then, if you want to output Perl strings, you must encode them first, see perlunitut and perlunifaq.

use Encode qw(encode);
use Encode::HanExtra;
# for example, printing to STDOUT

print encode('UTF-8', $perl_string); # in a Linux environment
print encode('GB18030', $perl_string); # in a Windows environment

I also want to advise you that since the year 2006 support for the national standard GB18030 is mandatory for all software products in the PRC - you have to install Encode::HanExtra from CPAN.

daxim