Lingua::Han2PinYin::Light - convert Chinese character to its pinyin.
use Lingua::Han2PinYin::Light; my $hanzi = "我"; # the Chinese character my $pinyin = han2pinyin($hanzi); # the corresponding spell #now $pinyin is 'wo'; my $juzi = "我是中国人"; my $juzi_pinyin = han2pinyin($juzi); #now $juzi_pinyin is 'wo shi zhong guo ren'); my @juzi = qq/我 是 中 国 人/; my @pinyin = han2pinyin(@juzi); #now @pinyin is ('wo', 'shi', 'zhong', 'guo', 'ren')
There is a Chinese document @ http://www.1313s.com/f/Han2PinYin.html. It tells why and how I write this module.
It's a light version, only can deal with 3660 characters([\xb0a1-\xd7f9]).
for the uncommon character, the distribution of its' coding is NOT continuous. So we can only convert the common character(3660).
if the character is polyphone(DuoYinZi), we can NOT point out the correct one.
Parameter can be scalar(one word or more) and array.
if it's a common character, it returns its pinyin/spell.
if not, it returns 'XX';
if you wantarray, it returns array else return scalar.
I'm not sure it works at all OS or different versions of perl.
Follows are tested, and feel free to report any bugs or corrections:
Win2000(SP4) + ActivePerl 5.8.5
Lingua::Han2PinYin
Fayland, fayland@gmail.com