in reply to Cross platform file I/O code
Blame it on the typewriters - better yet, that lever or button on the right side of them. The one used to start typing on the next line. When you activate it, it causes
In this Baudot code, two special characters were designated for a Carriage Return(0x02) and a Line Feed(0x08). Baudot code went the way of the dinosaur for reasons outside the scope of this discussion, but the CR and LF characters were adopted by ASCII with different values:
Why were they adopted? For printers of course. The concept of the tty was split into two - a monitor and a printer. At this point, it was up to the various operating systems to implement their actual use. Oops.CR = 0x0D = \015 = \r LF = 0x0A = \012 = \n
UPDATE: Disregard that last table, kept only for historical purposes. Here is a better table, one that shows how the three different operatiing systems interpret a logical newline (ps, thanks Mr. Stein =] )Macintosh: \r Windows : \r\n Unix : \n
This only causes problems when you transfer ASCII files around different operating systems as binary data, in which case you should use binmode - or when you are programming with sockets, in which case you will need to set $/ to '\015\012' or just use the exported globals $CRLF and CRLF() from the Socket or IO::Socket modules.Unix : \n = \012 Macintosh: \n = \015 Windows : \n = \012 if handled as ASCII Windows : \n = \015\012 if handled as binary
So, the next time you find yourself cursing this confusion, just take a look at this typewriter history tree and remember that we are only human, except arhuman. :)
Jeff
R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--
UPDATE: Thanks to the anonymous monk for clarifying things up.
REFERENCES:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A Little History on 0D0A
by indigo (Scribe) on Apr 01, 2001 at 00:00 UTC | |
|
Re: A Little History on 0D0A
by Anonymous Monk on Apr 01, 2001 at 13:38 UTC | |
|
Re: A Little History on 0D0A
by Beatnik (Parson) on Mar 31, 2001 at 23:17 UTC | |
|
Re: A Little History on 0D0A
by Anonymous Monk on Jun 21, 2008 at 15:31 UTC | |
by psini (Deacon) on Jun 21, 2008 at 15:43 UTC | |
by Anonymous Monk on Jan 27, 2014 at 17:20 UTC | |
by Anonymous Monk on Jan 19, 2017 at 11:54 UTC | |
by Anonymous Monk on May 18, 2017 at 11:15 UTC | |
by marto (Cardinal) on May 18, 2017 at 11:29 UTC |