Thank you for your support. I have managed yesterday. When you need it:

sub utf8_to_latin1      #converts from UTF8 to Latin1
{
        my $string = shift;
        my $format=$ENV{"UCFORMAT"}||('%lx');
        $string =~ s/([\xC0-\xDF])([\x80-\xBF])/sprintf ("%c",
hex(sprintf($format,
        unpack("c",$1)<<6&0x07C0|unpack("c",$2)&0x003F)))/ge;
        $string =~ s/([\xE0-\xEF])([\x80-\xBF])([\x80-\xBF])/sprintf("%c",
hex(sprintf($format,
        
unpack("c",$1)<<12&0xF000|unpack("c",$2)<<6&0x0FC0|unpack("c",$3)&0x003F)))/
ge;
        $string =~
s/([\xF0-\xF7])([\x80-\xBF])([\x80-\xBF])([\x80-\xBF])/sprintf ("%c", hex
(sprintf($format,
unpack("c",$1)<<18&0x1C0000|unpack("c",$2)<<12&0x3F000|
        unpack("c",$3)<<6&0x0FC0|unpack("c",$4)&0x003F)))/ge;
        return $string;
}


Dawid Zochowski
Professional Services

memIQ AG
Hans-Pinsel-Strasse 10a 
D-85540 Haar 
Tel.: +49 (0)89 456 39 334
Fax: +49 (0)89 456 39 500
Hdy: +49 (0)173 812 04 21
mail to: [EMAIL PROTECTED]
http://www.memiq.com



-----Original Message-----
From: Andrew McNaughton [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 13, 2000 1:03 AM
To: Benjamin Franz
Cc: David Zochowski; '[EMAIL PROTECTED]'
Subject: Re: UTF8 2 Latin1


On Tue, 12 Dec 2000, Benjamin Franz wrote:

> Date: Tue, 12 Dec 2000 11:03:36 -0800 (PST)
> From: Benjamin Franz <[EMAIL PROTECTED]>
> To: David Zochowski <[EMAIL PROTECTED]>
> Cc: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
> Subject: Re: UTF8 2 Latin1
> 
> On Tue, 12 Dec 2000, David Zochowski wrote:
> 
> > Hallo!
> > 
> > I do not know how to convert utf8 to latin1. I have Convert::Scalar
tried,
> > but it does not work for the 2bites chars (german chars). 
> > Could you help me? Do you know any other way to do it?
> 
> Look on CPAN for the module 'Unicode::MapUTF8'. Note: This will not fix
> the problem if you are trying to convert characters from UTF8 that do not
> exist in Latin1 (ISO-8859-1).

Markus Kuhn's 'transtab' is useful for this.  I've got a very simple perl
module which provides access to it if anyone wants a copy.  I'd welcome
some feedback.  email me if you want it.

Andrew McNaughton





--
Andrew McNaughton
Te Kete Ipurangi: The Online Learning Centre
[EMAIL PROTECTED]
Ph: 64 4 382 6500
Fax: 64 4 382 6509
Mobile: 021 323 076

PO Box 19-098
Wellington, NZ
http://www.tki.org.nz/

Reply via email to