develooper Front page | perl.unicode | Postings from January 2011

encoding(UTF16-LE) on Windows

Thread Next
From:
Erland Sommarskog
Date:
January 19, 2011 01:01
Subject:
encoding(UTF16-LE) on Windows
Message ID:
Xns9E709833BEFA4Yazorman@207.171.7.86
I'm on Windows and I have this small script:

   use strict;
   open F, '>:encoding(UTF-16LE)', "slask2.txt";
   print F "1\n2\n3\n";
   close F;

When I open the output in a hex editor I see

  31 00 0D 0A 00 32 00 0D 0A 00 33 0D 0A 00

I would expect to see:

  31 00 0D 00 0A 00 32 00 0D 00 0A 00 33 0D 00 0A 00

That is, I expect \n to be translated to 0D 00 0A 00, now it is translated 
to three bytes.

It seems like I'm missing something basic, but the information is spread out 
on several man-pages, and I have not been able to find where my error lies.

perl -v:

This is perl 5, version 12, subversion 2 (v5.12.2) built for MSWin32-x86-
multi-thread (with 8 registered patches, see perl -V for more detail)

Copyright 1987-2010, Larry Wall

Binary build 1202 [293621] provided by ActiveState 
http://www.ActiveState.com
Built Sep  6 2010 23:36:03

-- 
Erland Sommarskog, Stockholm, esquel@sommarskog.se

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About