Perl, text files, & \r

Christopher Rath christopher@rath.ca
Sun Jul 8 15:08:00 GMT 2001


<flame>
I personally resent the fact that perl tries to hide from me the fact that
MS-DOS text files use <CR><LF> and not just <LF> as their end of line
sequence.  The choice to translate and obscure reality as a default is
something I consider rather poorly thought out.  A file is just a file; it's
a collection of bits.   The fact that it contains structure should not be
imposed by the interpreter; rather it should be handled by the programmer.

The cygwin tools themselves (e.g., makeindex) don't attempt to deal with the
<CR><LF> issue, so why does perl?  The default behaviour should be NO
translation (i.e., binmode on).  If I want the computer to do something for
me then I'll make the request.  Perl's present behaviour is exactly the type
of parental attitude Microsoft so commonly displays and it is rather
unbecoming when it appears in perl.

My perl script deals properly with the content of the files it encounters;
however, when I wrote it I never accommodated perl's file I/O behaving in
such a fascist manner.
</flame>

=========== Christopher Rath == (613) 824-4584 ===========
       1371 Major Rd., Orleans, ON, Canada  K1E 1H3
=============== mailto:christopher@rath.ca ===============
  ``Hydrogen is a colourless, odourless gas which, given
  enough time, turns into people.'' --- Henry Hiebert
================== http://www.rath.ca/ ===================

-----Original Message-----
From: Michael A. Chase [ mailto:mchase@ix.netcom.com ]
Sent: 8 July, 2001 15:20
To: gp@familiehaase.de; Christopher Rath
Cc: cygwin@cygwin.com
Subject: Re: Perl, text files, & \r


----- Original Message -----
From: "Gerrit P. Haase" <gp@familiehaase.de>
To: "Christopher Rath" <christopher@rath.ca>
Cc: <cygwin@cygwin.com>
Sent: Sunday, July 08, 2001 06:40
Subject: RE: Perl, text files, & \r


> Christopher Rath schrieb am 2001-07-07, 23:13:
>
> > solution: use of the 'binmode' command.
>
> Would it help to set the environment settings CYGWIN=binmode ?
>
> [...]
> > I think this should be in the Cygwin FAQ.  Why this works can be found
on
> > pp. 53-55 and 147 of "Programming Perl 2nd Ed."
>
> Is it a cygwin issue or more a perl one?
> You can choice at setup time between 'unix(==binmode)' and
> 'windows(==textmode)' mode.
> You could mount with '-b' for binmode.
> It should work as it does on unixlike systems if you setup
> with binmode as default.

It's really a portable programming issue which affects Perl, Python, C, ...

If you know a file needs to be read or written without text modification, it
should be opened in binary mode or set to binary mode as early as possible.
The mount and CYGWIN binmode and textmode options are workarounds for
programs that didn't take that into account when they were originally
written.

--
Mac :})
** I normally forward private questions to the appropriate mail list. **
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list