First, you should make sure that your website are using config with $NonEnglish=1. Also, you'd better use 'UTF-8' encoding method for your pages.
Secondly, make sure you server has Encode module of Perl installed, then you just need to modify your code as following.
sub GetPageDirectory { my ($id) = @_; if ($id =~ /^([a-zA-Z])/) { return uc($1); } return "other"; }
sub GetPageDirectory { my ($id) = @_; if ($id =~ /^([a-zA-Z])/) { return uc($1); } return PinyinIndex($id); } sub PinyinIndex() { #created by Xuefeng Liu. my ($id)=@_; use Encode qw/encode decode from_to/; my $data = encode("gb2312", decode("utf8", $id)); $data=~s/\|//g; $data=~ s/(\W)/sprintf("%02X", unpack("C", $1))/eg; $data=~ /^(.{4})/; my $chr_value= hex($1); if( $chr_value < hex("B0A1") ) { return "other"; } if( $chr_value <= hex("B0C4")) { return "A"; } if( $chr_value <= hex("B2C0")) { return "B"; } if( $chr_value <= hex("B4ED")) { return "C"; } if( $chr_value <= hex("B6E9")) { return "D"; } if( $chr_value <= hex("B7A1")) { return "E"; } if( $chr_value <= hex("B8C0")) { return "F"; } if( $chr_value <= hex("B9FD")) { return "G"; } if( $chr_value <= hex("BBF6")) { return "H"; } if( $chr_value <= hex("BFA5")) { return "J"; } if( $chr_value <= hex("C0AB")) { return "K"; } if( $chr_value <= hex("C2E7")) { return "L"; } if( $chr_value <= hex("C4C2")) { return "M"; } if( $chr_value <= hex("C5B5")) { return "N"; } if( $chr_value <= hex("C5BD")) { return "O"; } if( $chr_value <= hex("C6D9")) { return "P"; } if( $chr_value <= hex("C8BA")) { return "Q"; } if( $chr_value <= hex("C8F5")) { return "R"; } if( $chr_value <= hex("CBF9")) { return "S"; } if( $chr_value <= hex("CDD9")) { return "T"; } if( $chr_value <= hex("CEF3")) { return "W"; } if( $chr_value <= hex("D188")) { return "X"; } if( $chr_value <= hex("D4D0")) { return "Y"; } if( $chr_value <= hex("D7F9")) { return "Z"; } return "other"; }
If you have problem, please feel free to contact with me, xfliu.math[at]gmail.com