perl 转汉字到拼音

2014-01-20

使用Lingua写的模块: pm link : search.cpan.org/~fayland/Lingua-Han-PinYin-0.15/lib/Lingua/Han/PinYin.pm

#!/usr/bin/perl -w
use Lingua::Han::PinYin();

sub getpinyin{
my @value = @_;
my $pinyin = '';
    for my $out (0 .. $#value){
       $pinyin .= $value[$out];
    }
   print "$pinyin";
}

open(FH,$ARGV[0]) or die "Can't find filename:$!";
while(<FH>)
{
   next if /^#/;
   my($filmname,$size) = split /\s+/;
   my $h2p = new Lingua::Han::PinYin();
   my @value = $h2p->han2pinyin("$filmname");
   getpinyin(@value);
   print "\t$size\n";
}

列表文件:

#name size/MB 叶问.mp4 578Mb 夺金.mp4 644Mb 遮天.txt 6Mb 龙门飞甲.ts 1.4Gb

处理:

[root@cz perl]# perl pinyin.pl liebiao.txt xiewen.mp4 578Mb duojin.mp4 644Mb zhetian.txt 6Mb longmenfeijia.ts 1.4Gb