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]

RE: Perl, text files, & \r


Hmm, doesn't sound like a cygwin related issue anymore.  Sounds like
what you want to do is call binmode once on each file you open.  The
cost to you is very small, and the number of scripts that don't want to
deal with the line ending differences that are portable because the
default is to hide the difference is huge.  Note that modern perl is
taking steps in the direction of more control over this sort of stuff
with the idea of line-disciplines.  In this particular case, perl
behaves the way the C runtime libraries of many DOS/Windows compilers
have been behaving for decades, with some small explicit distinction
between text and binary files and support for both.  "A file is just a
collection of bits" is _a_ definition, it's not _the_ definition.
"Translating and obscuring reality" is what an awful lot of software is
all about.  The idea that various 'real' I/O devices, including files on
disk, disks and printers are just a stream of bits is in fact, a
simplifying abstraction, and is considered one of the significant
innovations of Unix, oh, 30+ years ago.

stephan(speaking only for myself, and not representing my employer in
any official capacity);


-----Original Message-----
From: Christopher Rath [mailto:christopher@rath.ca] 
Sent: Sunday, July 08, 2001 3:09 PM
To: Cygwin Maillist
Cc: Michael A. Chase; gp@familiehaase.de
Subject: RE: Perl, text files, & \r



<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/


--
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/


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