Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

\n? \r\n? \x0d\x0a?

Status
Not open for further replies.

Kirsle

Programmer
Jan 21, 2006
1,179
US
I was hoping somebody could shed a little light on this:

Most of us just use \n in our code when we want a line break. But, \n actually inserts the native line break code for your OS, instead of a literal Line Feed, so that on Windows, a \n is actually a "\r\n".

Which brings up another subject: isn't explicitely writing \r\n redundant then, on a Windows machine? Because, "\r\n" would literally turn into "\r\r\n"

Or, should we start getting into the habit of using the hex escapes? i.e. using \x0a for line feeds and \x0d for carriage returns?

In my Tk::HyperText module, for instance, it always inserts \x0a into the text box when it wants a new line (because Linux's Perl Tk would show a carriage return as \x{d} in the text box).

So, the question: should we be using \n or \x0a? And should be stop using \r\n because we know it's redundant, and instead use \x0d\x0a?

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
just using \n sounds like the ticket.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Just using \n is good for portability. But you can still run into problems if you are reading a document created on another OS.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top