Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by karlgoethebier (Curate)
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»


Comment on Re: How to print Unix newlines in Strawberry Perl on Windows
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019788]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2014-08-20 14:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (115 votes), past polls