http://www.perlmonks.org?node_id=952948

chessgui has asked for the wisdom of the Perl Monks concerning the following question:

If I possess a character string for which the code page is known how do I convert it to a valid unicode string in Perl?

Replies are listed 'Best First'.
Re: Conversion between code page and unicode in Perl
by ikegami (Patriarch) on Feb 10, 2012 at 09:26 UTC

    If you want Unicode code points (replace 1252 with the code page in question),

    my $code_points = decode('cp1252', $cp1252_bytes);

    If you want UTF-16le, the encoding Windows calls "Unicode", continue with

    my $utf16le_bytes = encode('UTF-16le', $code_points);

    decode and encode are provided by Encode. It's from_to can combine decode+encode.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Conversion between code page and unicode in Perl
by Anonymous Monk on Feb 10, 2012 at 08:40 UTC