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

Re: [MacPerl] Recognizing Unix Line Breaks



Paul J. Schinder wrote:

>To most of "everyone else", \n means \015\012 (Microsoft is a monument to
>human stupidity in more ways than one).

I agree with the rest of that paragraph, which is why I deleted it.
However, I'm sure CRLF precedes MicroSnot DOS by a decade or so. It
certainly was used in CP/M, and judging by it's existence in various RFC,
dating back before anyone had dreamed of putting DOS machines on the
Internet, I would think other old OSes (VMS?) use it as well. In a wicked
way CRLF even makes sense on slow machines with slow output devices and
moderate storage. Just as \n makes sense on relatively fast machines with
slow output devices and moderate storage (Here, processing of \n into CRLF
is not a problem.) Today, it shouldn't really matter which one to use, so
we _should_ probably apply the Postel principle of liberal handling of
input and conservative generation of output. I love that principle.
Alas, there is no easy way to have Perl recognize all three of CRLF, CR and
LF as input line-breaks, is there?

BTW, I have noted that some HTTP servers do not send CRLF as they should,
and one one occasion a server didn't like CR at all in GET commands. Has
anyone else experienced this? This actually broke LWP, and I had no way to
force LWP to use a different line-break convention to deal with this
server, very apropos. I solved it by using sockets directly and writing my
own GET commands. (Also, judging from my observations, it seems Netscape
sends GET <URL> LF rather than GET <URL> CRLF. I know this is not very
MacPerl relevant, but I'd appreciate confirmation of this in private mail.)

>$/ doesn't do what you'd like \s to do.  $/ gets appended to *every* line
>you print, even when you don't really want it.

No it doesn't? Or what do you mean by "gets appended to *every* line"?

#! /usr/local/bin/perl -w
$/ = "THIS IS \$/!\n";

print "Foo";
print "Bar";

print "Foo$/";
print "Bar$/";
print "Foo","Bar";

prints (with MacPerl and A/UX Unix Perl):

"FooBarFooTHIS IS $/!
BarTHIS IS $/!
FooBar"

So actually, I'd think using $/ would work fine. Convincing people to use
this in modules however... :-)

Perhaps you thought of $\ which is the output record separator?

#! /usr/local/bin/perl -w

$\ = "THIS IS \$\\!\n";

print "Foo";
print "Bar";
print "Foo","Bar";

prints:
"FooTHIS IS $\!
BarTHIS IS $\!
FooBarTHIS IS $\!
"

>Agreed, and Perl is unusual in that it gives you tools to deal with this.
>Imagine having to do this in C.

Horrible.

-Lasse



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