Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   decode a string to "Perl's internal form" without Encode module? (http://www.velocityreviews.com/forums/t902044-decode-a-string-to-perls-internal-form-without-encode-module.html)

Raymundo 02-28-2007 05:56 AM

decode a string to "Perl's internal form" without Encode module?
 
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.


anno4000@radom.zrz.tu-berlin.de 02-28-2007 08:17 AM

Re: decode a string to "Perl's internal form" without Encode module?
 
Raymundo <gypark@gmail.com> wrote in comp.lang.perl.misc:
> 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

Ben Morrow 02-28-2007 10:34 AM

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

Quoth anno4000@radom.zrz.tu-berlin.de:
> Raymundo <gypark@gmail.com> wrote in comp.lang.perl.misc:
> > 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.


....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

--
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks] ben@morrow.me.uk

Raymundo 02-28-2007 05:08 PM

Re: decode a string to "Perl's internal form" without Encode module?
 
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


On 2월28일, 오후7시34분, Ben Morrow <b...@morrow.me..uk> wrote:
> Quoth anno4...@radom.zrz.tu-berlin.de:
>
>
>
>
>
> > Raymundo <gyp...@gmail.com> wrote in comp.lang.perl.misc:
> > > 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.

>
> ...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



anno4000@radom.zrz.tu-berlin.de 02-28-2007 07:12 PM

Re: decode a string to "Perl's internal form" without Encode module?
 
Raymundo <gypark@gmail.com> wrote in comp.lang.perl.misc:

[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


All times are GMT. The time now is 04:25 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.