Creating files with swedish chars

Posted by SweMart on 2006-10-30 13:21


I'm trying to create files containing swedish characters(ÅÄÖåäö) in WinXP Pro.

I've tried the following:

open(FILE,">" . encode("utf16le", "åäö-test.txt");
print FILE "test\n";

I've also tried to using the "Encode" module but I still can't get it to work(also tried ut8, utt16 and ibm850 encoding). Any pointers would be much appreciated. The actual program reads the file names from a SQLite database which uses unicode encoding.
Whatever encoding I chose the filenames look garbled, i.e "¥Ã¶" or "├ò├À".

Many thanks,

jeff.griffiths | Fri, 2006-11-10 15:27

What version of Perl are you using? With 5.8.8 on Ubuntu and using UTF-8 files, I seem to be able to handle these characters easily. So if 'swedish.txt' just contains ÅÄÖåäö, I can run this code and get the same characters in the second file:

use strict;
local $/;
open(FH, "< ./swedish.txt"); 
my $txt = ; 

open(FHTWO, "> ./swedish2.txt"); 
print FHTWO $txt;