RE: encoding(UTF16-LE) on Windows

[email protected] ("Jan Dubois") Fri, 21 Jan 2011 13:32:27 -0800
Newsgroups perl.unicode
Organization ActiveState Software Inc
Message-ID <[email protected]>
------=_NextPart_000_02FE_01CBB96F.A5356740
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

Depends on what you mean by =93correctly=94.  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=92t want =
the :crlf layer on non-Windows systems it is as easy as:

=20

                open(my $fh, =93:raw:encoding(UTF-16LE)=94, $filename) =
or die $!;

     binmode($fh, =93:crlf=94) if $^O eq =93MSWin32=94;

=20

Cheers,

-Jan

=20

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

=20

From: Bob Hallissy [mailto:[email protected]]=20
Sent: Thursday, January 20, 2011 7:40 PM
To: [email protected]
Subject: Re: encoding(UTF16-LE) on Windows

=20


Jan Dubois wrote:=20

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=20

  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


------=_NextPart_000_02FE_01CBB96F.A5356740
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta =
http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252"><meta name=3DGenerator content=3D"Microsoft Word =
14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Consolas;
	panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";
	color:black;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
pre
	{mso-style-priority:99;
	mso-style-link:"HTML Preformatted Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:"Courier New";
	color:black;}
span.HTMLPreformattedChar
	{mso-style-name:"HTML Preformatted Char";
	mso-style-priority:99;
	mso-style-link:"HTML Preformatted";
	font-family:Consolas;
	color:black;}
span.moz-txt-tag
	{mso-style-name:moz-txt-tag;}
span.EmailStyle20
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></head><body bgcolor=3Dwhite =
lang=3DEN-US link=3Dblue vlink=3Dpurple><div class=3DWordSection1><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>Depends on what you mean by =93correctly=94.=A0 It does work =
correctly as-is, creating output encoded as UTF-16LE with CR/LF line =
endings.=A0 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.=A0 Assuming you don=92t =
want the :crlf layer on non-Windows systems it is as easy =
as:<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 </span><span =
style=3D'font-size:11.0pt;font-family:"Courier New";color:black'>open(my =
$fh, =93:raw:encoding(UTF-16LE)=94, $filename) or die =
$!;<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Courier =
New";color:black'>=A0=A0=A0=A0 binmode($fh, =93:crlf=94) if $^O eq =
=93MSWin32=94;<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>Cheers,<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>-Jan<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>PS: I saw some discussion today that the :raw pseudo-layer in the =
open() call will also remove the buffering layer (it doesn=92t do that =
when you use it in a binmode() call). I=92ll try to remember to send a =
followup once I actually understand what is going =
on.<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><div =
style=3D'border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in =
4.0pt'><div><div style=3D'border:none;border-top:solid #B5C4DF =
1.0pt;padding:3.0pt 0in 0in 0in'><p class=3DMsoNormal><b><span =
style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowt=
ext'>From:</span></b><span =
style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowt=
ext'> Bob Hallissy [mailto:[email protected]] <br><b>Sent:</b> =
Thursday, January 20, 2011 7:40 PM<br><b>To:</b> =
[email protected]<br><b>Subject:</b> Re: encoding(UTF16-LE) on =
Windows<o:p></o:p></span></p></div></div><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal><br>Jan =
Dubois wrote: <o:p></o:p></p><pre>Files opened on Windows already have =
the :crlf layer pushed by default,<o:p></o:p></pre><pre>so you somehow =
need to get the :encoding layer <span =
class=3Dmoz-txt-tag><b>*</b></span><b>below<span =
class=3Dmoz-txt-tag>*</span></b> it.<o:p></o:p></pre><p =
class=3DMsoNormal><br>Is it possible to re-write the working statement =
<o:p></o:p></p><pre>=A0=A0open(my $fh, =
&quot;&gt;:raw:encoding(UTF-16LE):crlf&quot;, $filename) or die =
$!;<o:p></o:p></pre><p class=3DMsoNormal>in a way that works correctly =
on any platform (without referring to $^O) =
?<br><br>Bob<o:p></o:p></p></div></div></body></html>
------=_NextPart_000_02FE_01CBB96F.A5356740--