Thank you again,
:raw:encoding(UTF-16LE) didn't help. This produces 00 0A 00 as newline. It looks like correct Unicode but not same as need. Here is the output of a different setting using the PerlIO::get_layers($fh):
layers :raw:encoding(UTF-16LE):crlf:via(File::BOM):
unixencoding(UTF-16LE)utf8crlfutf8viautf8
layers :encoding(UTF-16LE):
unixcrlfencoding(UTF-16LE)utf8
:raw:encoding(UTF-16LE):
unixencoding(UTF-16LE)utf8
I found the solution in the activestate forum: http://community.activestate.com/forum-topic/creating-unicode-utf-16le.
You need to use File::BOM and open the file as following:
open my $fh, '>:raw:encoding(UTF-16LE):crlf:via(File::BOM)', 'file.reg
+';
The same problem is described there. I don't know what this line is doing, any comments of unicode and Perl insiders are welcome. I assume this writes newline using this File::BOM module and this way the byte order is correct.
My script is now writing pretty fine output. I exported the whole HKLM/Software and had only few differences. This is a value I can live with. If I export only the sub-tree of my interest the file is completely identical to the output of regedit.exe.
Thank you for your help. |