the conversion between Perl Chinese/Unicode/utf8/gb2312 encoding is a headache. I have summarized the following conversion methods for your reference.
# Author: jiangyujie <br/> Use utf8; <br/> Use encode; <br/> Use URI: escape; </P> <p> $/= "/N"; </P> <p> # utf8 encoding obtained from Unicode <br/> $ STR = '% u6536 '; <br/> $ STR = ~ S // % u ([0-9a-fa-f] {4})/Pack ("u", Hex ($1)/EG; <br/> $ STR = encode ("utf8", $ Str); <br/> Print UC unpack ("H *", $ Str ); </P> <p> # obtain gb2312 encoding From Unicode <br/> $ STR = '% u6536'; <br/> $ STR = ~ S // % u ([0-9a-fa-f] {4})/Pack ("u", Hex ($1)/EG; <br/> $ STR = encode ("gb2312", $ Str); <br/> Print UC unpack ("H *", $ Str ); </P> <p> # utf8 encoding obtained from Chinese <br/> $ STR = ""; <br/> Print uri_escape ($ Str ); </P> <p> # obtain Chinese characters from utf8 encoding <br/> $ utf8_str = uri_escape (""); <br/> Print uri_unescape ($ Str ); </P> <p> # obtain Perl Unicode from Chinese <br/> utf8: Decode ($ Str); <br/> @ chars = Split //, $ STR; <br/> foreach (@ chars) {<br/> printf "% x", ord ($ _ ); <Br/>}</P> <p> # obtain the standard Unicode from Chinese. <br/> $ A = "Chinese "; <br/> $ A = decode ("utf8", $ A); <br/> map {print "// U", sprintf ("% x ", $ _)} unpack ("u *", $ A); </P> <p> # obtain Chinese from standard Unicode <br/> $ STR = '% u6536 '; <br/> $ STR = ~ S // % u ([0-9a-fa-f] {4})/Pack ("u", Hex ($1)/EG; <br/> $ STR = encode ("utf8", $ Str); <br/> Print $ STR; </P> <p> # obtain Chinese from Perl Unicode <br/> my $ Unicode = "/X {505c}/X {8f66 }"; <br/> Print encode ("utf8", $ Unicode );