[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] When is \r really \n in MacPerl!?



Paul J. Schinder <schinder@pobox.com> wrote:

> The results of your script are exactly right for MacPerl, and it makes
> utter sense to do this under MacOS.

Although I am not in sync with the original poster, I have to drop in my
$0.02:

I am an Ex-DOS-User, so I am a bit tortured by line-endings. Under DOS
they do it in another way: they don't fiddle around with \r or \n (as it
is impossible: \n would than stand for two characters CRLF, and that
wouldn't be in sync with the definition of \n as one character), they do
it by introducing textmode/binmode. There is a similar thing in Perl:
you can open a file and switch to binmode. In Textmode, the IO-library
translates CRLF to \n on input and \n to CRLF on output. In binmode,
this translation is not done.

The result is mostly the same as in MacPerl for IO: I can just write \n
and get the correct results. But \n in binmode is still LF, as it should
be.

Actually I stumbled over this MacPerl specific \n-\r Problem some time
before when I had to import foreign textfiles that used DOS-Endings (I
resolved it by writing explicitly \x0A and \x0D instead auf \n and \r).

I would prefer the binmode/textmode approach over the \n-\r approach.
It's much more flexible (because you an decide _when_ to interpret
lineendings and when not). And since you most often use simple textfiles
in Perl, most of the time the textmode is ok. Only sometimes you need to
switch to binmode - and then it is essential (IMO) that you write that
explicitly into your code, because there _are_ systems out there, where
this is important (DOS, OS/2, WIN32 for example).

BTW: DOS-IO-Functions often accept all three line-endings (if _I_ write
them ;-) ) or at least two (if Borland writes them: CRLF and CR are
accepted, if the Rest of the World writes them: CRLF and LF are
accepted). This is very helpfull if you read in foreign textfiles: you
just don't care on input.

Oh, as I said, I would _prefer_ the other way. But of course, I _can_
live with the current approach. It's not perfect, but what piece of
software _is_ perfect?

bye, Georg

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch