Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Conversion between code page and unicode in Perl

by chessgui (Scribe)
on Feb 10, 2012 at 08:37 UTC ( #952948=perlquestion: print w/replies, xml ) Need Help??
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?
  • Comment on Conversion between code page and unicode in Perl

Replies are listed 'Best First'.
Re: Conversion between code page and unicode in Perl
by ikegami (Pope) 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.



      Thank you.

      This WORKS:


      $ucontent=Encode::decode('cp852',$ucontent);

      I've been waiting for this answer for hours.
        I've been waiting for this answer for hours.

        And why was it so hard to take a look at the docs in the meantime?

        It's right there in the mentioned tutorial, in the section "the actual 5 minute tutorial".

Re: Conversion between code page and unicode in Perl
by Anonymous Monk on Feb 10, 2012 at 08:40 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://952948]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
[1nickt]: tobyink perl -MTypes::Standard= is_Int -Mstrict -wE 'say 1 if is_Int 1.0'
[jdporter]: so that I can use the existing expand unix util. Otherwise, I'll probably use Text::Tabs.
[1nickt]: pryrt I guess I don;t really care if user 42 logs on as 42.0 ... more of an academic question at this point.
[LanX]: jdporter: open PIPE,'-|' ?
[LanX]: oh you want the result line by line?
[jdporter]: ok, LanX, then what?
[jdporter]: It doesn't have to be line by line. Just "my program" "writes" to the external prog and also/then "reads" from it.
LanX open (You are not allowed to open to a command that pipes both in and out, but see IPC::Open2, IPC::Open3, and Bidirectional Communication with Another Process in perlipc for alternatives.)
[jdporter]: IPC::Open2, I guess
[jdporter]: yes, that

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2017-05-24 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?