delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/09/13/03:28:24

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Sat, 13 Sep 2003 09:33:48 +0200
From: "Gerrit P. Haase" <gp AT familiehaase DOT de>
Reply-To: "Gerrit @ cygwin" <cygwin AT cygwin DOT com>
Organization: Esse keine toten Tiere
X-Priority: 3 (Normal)
Message-ID: <49980560211.20030913093348@familiehaase.de>
To: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
CC: Peter Westerstrom <peterw AT eonreality DOT se>, cygwin AT cygwin DOT com
Subject: Re: perl textmode newline problem
In-Reply-To: <Pine.GSO.4.56.0309041624210.1861@slinky.cs.nyu.edu>
References: <3F5798C8 DOT 1050806 AT eonreality DOT se>
<Pine DOT GSO DOT 4 DOT 56 DOT 0309041624210 DOT 1861 AT slinky DOT cs DOT nyu DOT edu>
MIME-Version: 1.0

Peter,

>> I can't get perl to write files in text mode with correct line feeds.
>>
>> My perl program:
>> #!/usr/bin/perl
>> open(F, "> test.txt") or die "can't open file";
>> print F "Foo\n";
>> print F "Bar\n";
>> close(F);
>>
>> Outputs newlines as 0x0A.
>>
>> But my C program:
>> #include <cstdio>
>> int main(int argc, char** argv)
>> {
>>         FILE *fp = fopen("test3.txt", "w");
>>         fprintf(fp, "Foo\n");
>>         fprintf(fp, "Bar\n");
>>         fclose(fp);
>>         return 0;
>> }
>>
>> Writes newlines as 0x0D 0x0A. Same output dir.

Please use the PERLIO layers, due to problems with PERLIO and
binmode() in perl I patched perl to default to PERLIO=unix, you can
override this by setting PERLIO in your environment to PERLIO=crlf
which will push the CRLF layer on top, perl will do conversion of \n
to \r\n automatically then.

$ ./perl_newline.pl

$ od -c test.txt
0000000   F   o   o  \n   B   a   r  \n
0000010

$ export PERLIO=crlf

$ ./perl_newline.pl

$ od -c test.txt
0000000   F   o   o  \r  \n   B   a   r  \r  \n
0000012


Gerrit
-- 
=^..^=


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019