This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: perl textmode newline problem


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]