This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
Re: perl textmode newline problem
- From: "Gerrit P. Haase" <gp at familiehaase dot de>
- To: Igor Pechtchanski <pechtcha at cs dot nyu dot edu>
- Cc: Peter Westerstrom <peterw at eonreality dot se>, cygwin at cygwin dot com
- Date: Sat, 13 Sep 2003 09:33:48 +0200
- Subject: Re: perl textmode newline problem
- Organization: Esse keine toten Tiere
- References: <3F5798C8.1050806@eonreality.se><Pine.GSO.4.56.0309041624210.1861@slinky.cs.nyu.edu>
- Reply-to: "Gerrit @ cygwin" <cygwin at cygwin dot com>
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/