实现的思路是,查表找到该字的所有读音,然后取首字母.
代码:
while (<DATA>) {chomp;my ($head, $all) = /^(.{3})(.*)$/;$all =~ s/^\s+//;### 只保留无音标号的首字母sub toshorter {my $str = $_[0];$str =~ s/ā|á|ǎ|à/a/g;$str =~ s/ē|é|ě|è/e/g;$str =~ s/ō|ó|ǒ|ò/o/g;$str =~ s/^([a-z]).*$/\1/;return $str;};my @tmp;for (split ',', $all) {push @tmp, toshorter($_);}$all = join ',', @tmp;###$pytable{$head} = $all;}sub getheadstr {@str = $_[0] =~ /.{3}/g;@res = ();sub loop {my ($no, $head) = @_;for (split ',', $pytable{$str[$no]}) {if ($no == $#str) {push @res, $head . $_;} else {loop($no + 1, $head . $_);}}}loop(0, "");undef %count;return join ' ', grep { ++$count{ $_ } < 2; } @res; }print "乐筠: " . getheadstr("乐筠") . "\n";print "梁炜: " . getheadstr("梁炜") . "\n";__DATA__数据太长,另附
数据在此