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

Fratres doctissimi,

I am unfortunate enough to have to use a Windows box at work. I was trying to write a Perl program that extracts data from DOS-encoded text files and puts them into Excel via OLE. However, the Exce file contained garbage instead of Hungarian accents.

(Now, i must admit I am very lame for Microsux-based code pages. Long ago I thought ISO-8859-1 is DOS and ISO-8859-2 is Windows. Later on I believed cp852 is DOS and cp1250 is Windows. Even later on I believed cp437 is DOS and cp1252 is Windows... Now I believe I am either a total asshole or people do mean different things when they so deceptively simply say "CSV file (MS-DOS)". So I have now simpler metaphors: "DOS encoding" is what FAR Manager calls DOS encoding. "Windows encoding" is what FAR Manager calls Windows encoding. Period. :-) )

So I opened up FAR Manager, a typed up a Perl program, in strictly DOS encoding, to test all possible encodings:

use Encode; use Win32::OLE; $ex = Win32::OLE->new('Excel.Application'); $book = $ex->Workbooks->Add; $sheet = $book->Worksheets(1); $text="árvíztűrő tükörfúrógép"; @encodings= Encode->encodings(":all"); $line=1; foreach (@encodings) { $sheet->Cells($line++,1)->{Value}=$_; $sheet->Cells($line-1,2)->{Value}=encode($_,$text); }; $book->SaveAs('c:\test.xls');


This put all available encodins and the usual pseudoword used to test all Hungarian accents: 'árvíztűrő tükörfúrógép' (meaning a drilling machine that drills mirrors and is able to survive floods :-) ). Now: ALL of the output was wrong. It meant that on my box it is simply not possible to convert a DOS text to Windows. Maybe not all necessary code pages were installed. Maybe it is a bad idea to convert a Hungarian-accented text with US English Windows. I dunno. But it's strange.

Semper voster,

Shenpen

UPDATE: now looking at "árvíztűrő" even my Linux/Gnome/Galeon box has some problem with accents...

Replies are listed 'Best First'.
Re: Dos -> Windows code table conversion
by ysth (Canon) on Aug 10, 2004 at 20:14 UTC
    I had some trouble getting Encode::encodings to work last time I tried it. You may be better off trying specific encodings. For the edification of the listening audience, would you mind showing what:
    use Data::Dumper; $Data::Dumper::Useqq = 1; print Dumper $text;
    shows?