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

Re: [MacPerl] Recognizing Unix Line Breaks



>I'm quite an amatuer at perl.. so here's a (hopefully) simple question for
>you all.
>
>How can I get mac perl to regonize Unix line breaks as such..  it seems to
>read them in as an unknown character.  I do most of my text editing with
>BBEdit and its defaulted to Unix (as it saves a lot of frustration when
>uploading scripts and config files) .. but I have to change back over to
>Macintosh to import a file into Mac Perl.
>
>Any help would be greatly appreciated

Of course you have already noted that \r is \012 and \n is \015, the
reverse from Unix.

The simplest solution, providing you have no special reason to use Unix
newlines in BBEdit, is not to use Unix newlines.

One solution that will allow you to use Unix newlines, would be to set $/
to '\012', but it is not completely foolproof, I'm sure there are modules
(I know of one old one, at least [1]) that locally reassign $/, and others
may rely on hardcoded \r or more probable \n, doing what you don't want.
You may accidentally type \n where you should have typed \012 or $/, so
this is not optimal.

I do some cross-platform development between Unix (Good old A/UX, but soon
also IRIX) and the Mac, and I must say that the MPW convention used by
MacPerl to reverse \r and \n sometimes is irritating. Symantec and
Metrowerks give us a choice whether to use the MPW C convention of swapping
the meaning of \n and \r or use \n to mean LF as God and Ritchie intended.
I for one would like to have that choice in MacPerl as well. (Sometimes I
want this choice in Unix Perl too, BTW. I use CAP for fileserver, but with
no CR-LF translation of text files. So any server-manipulation of
Mac-stored files is cumbersome.)

I think this is actually a general problem: Perl handles bytes, not
characters, so a similar problem exists with for instance Unicode
characters. How does Perl deal with two-byte characters? (I know this is
not MacPerl specific, but it is certainly relevant.)

Anyway, an option simply to use \n as \012 and \r as \015 in MacPerl would
be very nice IMHO. Ideally, this could be set by each script as an option
on the #! line, and would work with Unix Perl as well, the option letter b
(for backslash) seems appropriate and is currently unused. Default
behaviour could be set in the Preferences for MacPerl.

-Lasse



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