<?xml version="1.0" encoding="windows-1252"?>
<node id="102815" title="Answer: How do I convert a string to Unicode and back (v5.005_03)?" created="2001-08-07 15:45:49" updated="2005-08-13 23:04:29">
<type id="1888">
categorized answer</type>
<author id="11732">
QandAEditors</author>
<data>
<field name="doctext">
I should warn you that while this code may work for ascii, it most definitely will not work for other character sets and/or encodings.
&lt;p&gt;
You can use the Unicode::Map module like this:
&lt;pre&gt;
   perl -MUnicode::Map -e'print Unicode::Map-&gt;new(shift)-&gt;to8(&lt;&gt;)' 
&lt;/pre&gt;
There is also to16() if you need utf16.
&lt;p&gt;
Note that not all mappings are round-trip, i.e. you won't necessarily get back what you put in if
you try to "undo" the conversion.
&lt;p&gt;
For lots and lots of information on dealing with complex character set and encoding issues, see Ken Lunde's excellent book CJKV Information Processing from O'Reilly.
&lt;p&gt;
Or to skip the reading, you can just go to &lt;a href="ftp://ftp.oreilly.com/pub/examples/nutshell/cjkv/"&gt; the examples&lt;/a&gt;
and look at the perl directory.
&lt;p&gt;

</field>
<field name="parent_node">
36788</field>
</data>
</node>
