http://www.perlmonks.org?node_id=971863


in reply to Native newline encoding

Besides using a table to infer it from $^O, is there any other way to detect it?

It's not neat, but you can actually write a newline to a file and then read it in binmode:

use warnings; use strict; open FH, '>', 'out.txt' or die $!; print FH "\n"; close FH; open FH, '<', 'out.txt' or die $!; binmode(FH); my $stuff = do { local $/; <FH> }; print unpack('H*', $stuff), "\n";

Tested on Windows, where it prints 0d0a and on Linux where it prints 0a.

You could clean it up, use File::Temp... whatever. But, unfortunately, you can't get by with an in memory file or IO::Scalar.

-sauoq
"My two cents aren't worth a dime.";