|No such thing as a small change|
Re: CRLF questionby ELISHEVA (Prior)
|on Mar 08, 2011 at 09:09 UTC||Need Help??|
On a sheet of paper we're accustom to dividing the page up into lines. Data is just a run of bytes, but we still like the notion of "lines", so during the history of computing there have been a number of different characters and character strings that have been "standard" for marking the end of a logical line of input.
On some systems, including systems that inherit from DOS, the end of line marker is two characters: a carriage return character followed by a line feed character. In your code this would be "\r\n". \r is the carriage return character and \n is the new line character. In technical documents this sequence is often referred to as CRLF. CR is the carriage return character. LF is the new line character.
This two character sequence is duplication of the mechanical steps needed to create a new line on a typewriter or other printing device. If you have ever used an old manual typewriter you may remember that two stroke action: push the roller to the right (carriage return) and advance a line (a lever on the left).
Of course, since this end of line is really just a logical end of line, we don't really need those two mechanical control characters. Other operating systems developed the convention that a new-line character was enough to represent the logical end of line. Computers working with data in memory don't need to push a roller back to the beginning of the line so CR is redundant. Consequently, unix and linux files use only a "\n"
There are also other end-of-line conventions, for example, Mac Classic and IBM mainframes used 0x15 (CR). For the gory details see Newline.
I know it has to do something with encoding ...Also seen it been used as a Module
In Perl, CRLF shows up as part of IO. If you open a file handle in text mode, Perl automatically converts CRLF in the input stream to LF ("\n") when it reads in input. When it prints to a text mode file handle it does the reverse, converting LF to CRLF.
You can find out whether your file handle is doing automatic conversion by calling PerlIO::get_layers. If one of the array elements is ":crlf", then your file handle is doing conversion for you.