Re: Writing UTF-8 file under Windows



t_lawetta@xxxxxxxxx writes:

Happy New Year,

Whatever I try to write a UTF-8 file, I always end up with UTF-16LE
with the "FF FE" BOM at the beginning and 2 bytes per character.

I am reading strings from an external resource and try to write to
files.

my $string_with_special_chars = "Château Müller\nGarçon";
open F, ">:utf8", "test.txt";
print F $string_with_special_chars;
close F;

Tried it both on Linux (Perl 5.8.6) and Windows (Perl 5.8.7).

Just a data point. I can't reproduce your problem using Perl 5.8.7 on
Linux, although I have to either:

(a) tell Perl the source is UTF-8 with "use utf8;", or
(b) re-write the string using the encoding my Perl expects.

You can, of course, just use Unicode code points in strings:
"Ch\x{E2}teau..." and then you don't need to worry...

--
Ben.
.



Relevant Pages

  • Writing UTF-8 file under Windows
    ... Whatever I try to write a UTF-8 file, I always end up with UTF-16LE ... with the "FF FE" BOM at the beginning and 2 bytes per character. ... I am reading strings from an external resource and try to write to ... Why does Perl add it? ...
    (comp.lang.perl.misc)
  • Re: Writing UTF-8 file under Windows
    ... Whatever I try to write a UTF-8 file, I always end up with UTF-16LE ... I am reading strings from an external resource and try to write to ... re-write the string using the encoding my Perl expects. ... although I can't be bothered to re-read the UTF8 encoding algorithms to work out manually if the hexdump values agree with the `file` command's verdict. ...
    (comp.lang.perl.misc)
  • Re: can I replace a string in all Matlab .m files under a folder?
    ... How to write a program in Matlab to change the strings ... maybe the Perl in Matlab can help? ... the command that follows is to be executed. ...
    (comp.soft-sys.matlab)
  • Re: can I replace a string in all Matlab .m files under a folder?
    ... How to write a program in Matlab to change the strings ... maybe the Perl in Matlab can help? ... the command that follows is to be executed. ...
    (comp.soft-sys.matlab)
  • Re: Math
    ... converting them to strings, then back, the precision will be lost. ... following instructions from perl. ... involve steps performed by the C compiler. ...
    (comp.lang.perl.misc)