Skip to content

Instantly share code, notes, and snippets.

@terrencehan
Created October 24, 2012 13:27
Show Gist options
  • Save terrencehan/3946050 to your computer and use it in GitHub Desktop.
Save terrencehan/3946050 to your computer and use it in GitHub Desktop.
#你在使用这个代码之前先要把输入文件转换成UTF-8的编码
open $in, "<", "a.txt";
while (<$in>) {
chomp;
( $city, $pinyin ) = split;
$city .= "";
$hash{$city} = $pinyin;
}
$citys = join "|", keys %hash;
open $in, "<", "IPData.txt";
open $out, ">", "out.txt";
while (<$in>) {
s/($citys)/$hash{$&}/g;
print $out $_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment