Depends on what you mean by “correctly”.  It does work correctly as-is, 
creating output encoded as UTF-16LE with CR/LF line endings.
If you want different layers on different operating systems, then you will need 
to tell the interpreter what exactly it is you want.
Which means you probably have to look at $^O.  Assuming you don’t want the 
:crlf layer on non-Windows systems it is as easy as:

 

                open(my $fh, “:raw:encoding(UTF-16LE)”, $filename) or die $!;

     binmode($fh, “:crlf”) if $^O eq “MSWin32”;

 

Cheers,

-Jan

 

PS: I saw some discussion today that the :raw pseudo-layer in the open() call 
will also remove the buffering layer (it doesn’t do
that when you use it in a binmode() call). I’ll try to remember to send a 
followup once I actually understand what is going on.

 

From: Bob Hallissy [mailto:bob_halli...@sil.org] 
Sent: Thursday, January 20, 2011 7:40 PM
To: perl-unicode@perl.org
Subject: Re: encoding(UTF16-LE) on Windows

 


Jan Dubois wrote: 

Files opened on Windows already have the :crlf layer pushed by default,
so you somehow need to get the :encoding layer *below* it.


Is it possible to re-write the working statement 

  open(my $fh, ">:raw:encoding(UTF-16LE):crlf", $filename) or die $!;

in a way that works correctly on any platform (without referring to $^O) ?

Bob

Reply via email to