in reply to Re^4: Win32 registry export
in thread Win32 registry export

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.

Replies are listed 'Best First'.
Re^6: Win32 registry export
by wwe (Friar) on Jun 17, 2010 at 15:33 UTC
    Just raed the post of ikegami where an other solution was mentioned: U-DOS to DOS file conversion '>:raw:perlio:encoding(UTF-16le):crlf' tested this with the code:
    open my $fh4, '>:raw:perlio:encoding(UTF-16le):crlf', 'file4.txt' or d +ie "$!"; print {$fh4} "\x{FEFF}"; print $fh4 "AB\n"; print $fh4 "CD\n";
    and it looks like newlines are good here.