Hi,
after I got a workaround from $Bill I experimented a little more and found out
that the error MUST be in some PERLIO
part, because Encode does its job well!
Have a nice weekend,
Axel
My solution now looks this way:
use Encode qw (encode decode);
use strict;
use Unicode::String qw (utf8 latin1 utf16);
my (@encodings);
sub DisplayEncodings {
my (@list) = Encode->encodings (':all');
my ($elem);
# foreach $elem (@list) {
# printf "%s\n", $elem;
# }
@encodings = @list;
}
sub readFile {
my ($filename, $encoding) = @_;
unless ($encoding) {
$encoding = 'iso-8859-1';
}
open (my $file, "<:encoding($encoding)", $filename);
my (@content) = <$file>;
close ($file);
if (wantarray ()) {
return (@content)
}
else {
return (join ('',@content));
}
}
sub _writebin {
my ($filename, $octets) = @_;
open (FILE, ">$filename");
binmode (FILE);
print FILE $octets;
close (FILE);
}
sub writeFile {
my ($filename, $encoding, $pContent, $DOS) = @_;
my @found = grep (/$encoding/i, @encodings);
my ($results) = scalar (@found);
unless ($results) {
die ("Unknown encoding : $encoding\n");
}
if ($results > 1) {
@found = grep (/^$encoding$/i, @encodings);
($results) = scalar (@found);
}
if ($results != 1) {
die ("Ambiguous encoding : $encoding -> (@found)\n");
}
else {
$encoding = $found[0];
}
my ($type) = ref ($pContent);
unless ($type =~ /ARRAY|SCALAR/) {
die ("WRITEFILE: No method to encode : $type\n");
}
my ($utf) = "";
if ($type eq 'ARRAY') {
$utf = join ("", @{$pContent});
}
else {
$utf = $$pContent;
}
if ($DOS) {
$utf =~ s/\n/\r\n/sg;
}
my ($octets) = encode ($encoding, $utf);
_writebin ($filename, $octets);
}
DisplayEncodings ();
my $content = readFile ('master.tx_');
writeFile ('test.8ut_', 'utf8', \$content, 'DOS');
writeFile ('test.16ut_', 'UTF-16', \$content, 'DOS');
__END__
----------------------------------------------------------------------
S y s K o n n e c t G m b H
A Marvell Company
Siemensstr. 23
D-76275 Ettlingen
----------------------------------------------------------------------
Axel Mock
Software Engineer
phone: +49 7243 502 319
fax: +49 7243 502 931
email: [EMAIL PROTECTED]
http://www.syskonnect.de
-----------------------------------------------------------------------
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs