开发者

How can I embede chinese characters in my Perl source?

开发者 https://www.devze.com 2022-12-15 01:54 出处:网络
In my script I need to \"qw\" some chinese character int开发者_如何学编程o a string .when I run the script ,

In my script I need to "qw" some chinese character int开发者_如何学编程o 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 .


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消