in reply to Re^5: Parsing a text file
in thread Parsing a text file
You (and Skeeve) seem to be confused about the difference between the use of "\r" and "\n" in file I/O and their use in regular expressions.
It is a very confusing area, not made any easier by some very confused documentation. On this topic perlop says:
All systems use the virtual "\n" to represent a line terminator, called a "newline". ... In general, use "\n" when you mean a "newline" for your system, but use the literal ASCII when you need an exact character. ... If you get in the habit of using "\n" for networking, you may be burned some day.and perlport says:
Perl uses \n to represent the "logical" newline, where what is logical may depend on the platform in use. In MacPerl, \n always means \015. In DOSish perls, \n usually means \012, but when accessing a file in "text" mode, STDIO translates it to (or from) \015\012, depending on whether you're reading or writing. ...Note that this is 5.10.0 documentation.
Once upon a time, Perl really did have different values for "\n" in strings, and that was the way it adapted to different systems -- there was no translation of incoming characters. These days all that malarky is better done at the PerlIO layer. But I believe that MacPerl, however historic, does it the old way. That really is what the documentation means when it refers to the "logical" or "virtual" newline. Also, "\n" is referred to as "newline" or NL, not LF. (Because this is such an unusual approach one tends to read past these little words -- and that's not helped by the jumbling together of what "\n" means, what different operating systems do, and what Perl may or may not do in the middle.)
Now, you and I have never seen a system where "\r\n" ne "\x0D\x0A", but the documentation continues to state that it's a possibility.
|
|---|