in reply to perl read a file on Windows is very strange

This looks as if your file is in UTF-16LE encoding. Use the following to read it:

my $filename = "C:\\TEMP\\PT_TEST_STAT_EXP_export.log"; open my $fh, '<:encoding(UTF-16LE)', $filename or die "Couldn't read '$filename': $! / $^E"; while (<$fh>) { ... };

Replies are listed 'Best First'.
Re^2: perl read a file on Windows is very strange
by ikegami (Patriarch) on Nov 22, 2010 at 22:40 UTC

    That will fail to convert CR LF to LF even though :crlf is used, and it will corrupt a number of character combinations. (Specifically, the character U+0A0D and pairs of the form U+0Dxx U+xx0A.)

    Fix if you want CR LF ⇒ LF conversion:

    open my $fh, '<:raw:perlio:encoding(UTF-16LE):crlf', $filename or die "Couldn't read '$filename': $! / $^E";

    Fix if you want to leave CR LF intact:

    open my $fh, '<:raw:perlio:encoding(UTF-16LE)', $filename or die "Couldn't read '$filename': $! / $^E";

    (Mind you, corruption is very unlikely to occur since you'd have to be dealing with Malayalam characters. The non-functioning :crlf layer a more likely problem.)

    It's unfortunate that one has to go through these shenanigans when dealing with non-ASCII encodings.

      PerlIsFun
      Thank you very much. It works like charm!