decode a string to "Perl's internal form" without Encode module?


R

Raymundo

Hello,

At first, I'm sorry that I'm not good at English. :)

There is a string which is encoded with UTF-8, EUC-KR(Korean), EUC-JP,
or any other encoding scheme.

I want to decode it so that it become a string in "Perl's internal
form" (that is, unicode form.. is it so called "utf8"?).

For example,
$octets = "°¡³ª"; # 2 Korean characters, sequence of 6 Bytes
according to UTF-8
$string = "\x{AC00}\x{B098}"; # 2 Unicode characters. I want to get
this from $octets

It can be done easily using Encode module:
use Encode qw(decode);

$string = decode("UTF-8", $octets);

My question is, if I don't have Encode module in my server and I have
Text::Iconv module instead, Can I do the same thing using it? If I
can, how?

use Text::Iconv;

$converter = Text::Iconv->new("UTF-8", to-ENCODING);
$string = $converter->convert($octets);

What do I have to write for "to-ENCODING"?

I tried to "UNICODE" but Text::Iconv seemed to regard "UNICODE" as
"UCS-2LE"...

Any advice would be appreciated,

Raymundo at South Korea.
 
Ad

Advertisements

A

anno4000

Raymundo said:
Hello,

At first, I'm sorry that I'm not good at English. :)

There is a string which is encoded with UTF-8, EUC-KR(Korean), EUC-JP,
or any other encoding scheme.

I want to decode it so that it become a string in "Perl's internal
form" (that is, unicode form.. is it so called "utf8"?).

For example,
$octets = "°¡³ª"; # 2 Korean characters, sequence of 6 Bytes
according to UTF-8
$string = "\x{AC00}\x{B098}"; # 2 Unicode characters. I want to get
this from $octets

It can be done easily using Encode module:
use Encode qw(decode);

$string = decode("UTF-8", $octets);

My question is, if I don't have Encode module in my server and I have

You have the Encode module, it is part of every complete Perl
installation.
Text::Iconv module instead, Can I do the same thing using it? If I
can, how?

I don't know the Text::Iconv module, so I can't answer that. If Encode
works for you, use that.

Anno
 
B

Ben Morrow

Quoth (e-mail address removed)-berlin.de:
You have the Encode module, it is part of every complete Perl
installation.

....from 5.8 onwards. If you are stuck with 5.6, you should be aware that
that version of Perl did not handle Unicode at all internally, and you
really ought to upgrade.

Ben
 
R

Raymundo

Hmm... I have seen a web-hosting server in which Perl 5.6 was
installed and there wasn't Encode module. :-D

Anyway, thanks to your advices.

Raymundo at South Korea
 
Ad

Advertisements

A

anno4000

[please don't top-post]
Hmm... I have seen a web-hosting server in which Perl 5.6 was
installed and there wasn't Encode module. :-D

From your original posting:

I want to decode it so that it become a string in "Perl's internal
form" (that is, unicode form.. is it so called "utf8"?).

That implies a Perl that does include Encode.

[tofu snipped]

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top