"Jan Dubois" (jand(_at_)activestate(_dot_)com) writes:
You need to stack the I/O layers in the right order. The :encoding()
layer needs to come last (be at the bottom of the stack), *after* the
:crlf layer adds the additional carriage returns. The way to pop the
default :crlf layer is to start out with the :raw pseudo-layer:
open(my $fh, ">:raw:encoding(UTF-16LE):crlf", $filename) or die $!;
So this works. But this does not:
use strict;
open F, '>slask.out';
binmode(F, ':raw:encoding(UTF16-LE):crlf');
print F "Alfa\nBeta\nGamma\n";
Looking at the file in a binary editor, I see:
41 00 6C 00 66 00 61 00 0D 0A 00 42 00 65 00 74
00 61 00 0D 0A 00 47 00 61 00 6D 00 6D 00 61 00
0D 0A 00
In total 35 bytes. Which is a very odd number for a UTF16 file.
--
Erland Sommarskog, Stockholm, esquel(_at_)sommarskog(_dot_)se