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.";
"My two cents aren't worth a dime.";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Native newline encoding
by salva (Canon) on May 23, 2012 at 08:33 UTC | |
Re^2: Native newline encoding
by BrowserUk (Patriarch) on May 22, 2012 at 23:46 UTC | |
by sauoq (Abbot) on May 23, 2012 at 00:21 UTC | |
by BrowserUk (Patriarch) on May 23, 2012 at 00:43 UTC | |
by sauoq (Abbot) on May 23, 2012 at 01:08 UTC | |
by BrowserUk (Patriarch) on May 23, 2012 at 01:29 UTC | |
|
In Section
Seekers of Perl Wisdom