Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: How to print Unix newlines in Strawberry Perl on Windows

by karlgoethebier (Monsignor)
on Feb 20, 2013 at 14:28 UTC ( #1019788=note: print w/replies, xml ) Need Help??

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»

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019788]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2018-06-20 13:57 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.