Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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

by karlgoethebier (Parson)
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2016-10-26 10:23 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (340 votes). Check out past polls.