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


in reply to How to print Unix newlines in Strawberry Perl on Windows

"...force the script to write Unix newlines "\n" only?"

Perhaps like this:

#!c:/perl/bin/perl.exe use Data::Dumper; use strict; use warnings; my $string = qq(foo\nbar\n); open my $fh, '>', "dos.txt"; my @layers = PerlIO::get_layers($fh, output => 1); # edit print Dumper(\@layers); print $fh $string; close $fh; open $fh, '>:pop', "unix.txt"; @layers = PerlIO::get_layers($fh, output => 1); print Dumper(\@layers); print $fh $string; close $fh; __END__ $VAR1 = [ 'unix', 'crlf' ]; $VAR1 = 'unix'; $ hexdump.exe -c dos.txt 0000000 f o o \r \n b a r \r \n 000000a $ hexdump.exe -c unix.txt 0000000 f o o \n b a r \n 0000008

Update: See also PerlIO and Get record separator of a file. And thanks to davido.

Update2: Funky question: How can i do the same thing using IO::All? I've been playing around with it but i don't have a real plan for the moment. Perhaps i don't understand the manual. Or i miss something, as you like.

Update3: (awkward)

use IO::All; io("io.txt")->binmode(':unix')->print($string); __END__ $ hexdump.exe -c io.txt 0000000 f o o \n b a r \n 0000008

Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»