in reply to Re: script inserts \x00 bytes on WinXP
in thread script inserts \x00 bytes on WinXP

I think you meant that as a debugging tool? Why else would you do the conversion so late. Here's what the final code should probably look like:
... my $content; { open(my $fin, '<:encoding(UTF-16le)', $opt_i) or die "$0 : cannot read input file \"$opt_i\"\n"; local $/; $content = <$fin>; } ... { open(my $fout, '>:encoding(iso-latin-1)', $opt_o) or die "$0 : cannot write output file \"$opt_o\"\n"; print $fout join("\n", @sorted); }

Replies are listed 'Best First'.
Re^3: script inserts \x00 bytes on WinXP
by dwhite20899 (Friar) on Sep 06, 2008 at 01:38 UTC
    the output file contains one huge line of

    \x{4445}\x{3035}\x{533b}\x{676f}\x{203b}\x{2e34}\x{4e37}\x{6475}\x{736f}\x{203b}\x{6f43}

    Seriously, an "od -c" of the output file shows this:

    0000000 \ x { 7 6 4 5 } \ x { 6 e 6 5 + } 0000020 \ x { 6 f 7 4 } \ x { 4 2 2 0 + } 0000040 \ x { 7 1 7 5 } \ x { 6 5 7 5 + } 0000060 \ x { 2 0 3 b } \ x { 5 f 5 2 + } 0000100 \ x { 7 5 5 4 } \ x { 6 2 7 2 + }

    I actually got my hands on a WinXP machine running ActivePerl and ran the script with this code on XP, and got the above output.

    Horrible thing is (for my friend) when I run my original script on XP, it works like I expect - NOT producing the \x00 bytes! I don't understand this, and I can't replicate it, and I can't visit him (10 time zones away) to see WTF is going on.

      It's not Perl. The input file he used is different than yours, the output file he gave you is not the output he really got, or the script he used is different. The most likely explanation is that somewhere before or after the script was run, the input or output file was converted to UTF-16.