Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) 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.

You can also gain explicit control over whether or not a file handle does the CRLF to LF conversions, by playing around with the second parameter of open or by using the binmode command.

I'm not sure where you have seen it used as a module, i.e. use crlf. Perhaps another monk can inform us. A search on both http://perldoc.perl.org and CPAN came up dry for me.


In reply to Re: CRLF question by ELISHEVA
in thread CRLF question by Sary

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-25 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found