SPUG: lenght of string

Fred Morris m3047 at inwa.net
Wed Oct 6 05:51:58 CDT 2004

Not intentionally quoting out of context..

At 3:12 PM 10/5/04, Yitzchak Scott-Thoennes wrote:
>On Tue, Oct 05, 2004 at 02:31:01PM -0700, Ken Clarke <kenslinux at shaw.ca> wrote:
>> This snippet reports the length as 3 bytes when in fact it's 4:
>> "\x31\x0D\x0A\x33"
>> my $string = "1\n2";
>I think you are under a misapprehension.
>It really is just 3 bytes, but if you output it to a filehandle that
>does crlf conversion, you will get 4 bytes of output.  Everything is
>designed so that a program only has to worry about a single line-end
>character; CR's get stripped off as you read things in and added as
>you write things out.

No they aren't!? :-p

Actually I suspect you are correct in this specific case, but in the
tradition of the language typically used to specify RFCs I think "you will"
(must) is overstating the case and is more likely "you may".

Recall that the original poster was specifically referring to the context
of computing the length for a Content-Length header. Here's the interesting
thing: although it is widely ignored, all of the protocols which I recall
which utilize a Content-Length header specify \r\n as the official line
terminator (a fact which warms my impact printer, mechanical control code,
dinosaur lizard heart).

>If you are needing to count actual bytes of output, you may want to
>use a binmode filehandle and just manually use "\r\n" yourself (or
>"\015\012" if you have to worry about old Macs.)

See above...

As a further example 821/822 (not sure about son-of-821/822) has specific
admonitions against bare LFs although in the grand tradition most MTAs have
been willing to overlook this. If an MTA or other server isn't willing to
overlook these sorts of things, then it obviously has two options: fix it
or reject it. A strict reading of various RFCs would seem to indicate a
general bias towards rejection rather than repair (but only in those cases
where acceptance is not, well, acceptable), which may be overstating the
case as well, perhaps better to say that if you "repair" you are no longer
"forwarding". (Fixing the blame on ActiveState may be misplaced.) (Repairs
which are broken is probably the rationale for the bias towards rejection.)

Off topic: have you actually ever found a standard for "crlf conversion"?



More information about the spug-list mailing list