Solved

\n does not bring me to a new line

Posted on 1998-08-12
4
180 Views
Last Modified: 2010-03-05
If I have the following code, it all gets printed on the same line.

print "hello\n";
print "next line";

output looks like this:

hellonext line

Why would that be?

I have build 316 of the code. This is the latest version I've seen. Is there something I'm doing wrong?

Thanks.
0
Comment
Question by:johnsm
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
sybe earned 50 total points
ID: 1209242
In your browser it will look like that, because your browser reads HTML. If you want it to be displayed on a next line in your browser, use:

print "hello<br>\n";
print "next line";
0
 
LVL 1

Author Comment

by:johnsm
ID: 1209243
That worked.

I had originally tried adding the <br>, but it was always outside of the quotes and simply produced a <br> (literally) on my page. I didn't think of puting it inside the quotes.

Now this brings up another point. I don't really need the \n if the <br> is what is being used to do a new line.

Hmmm. Interesting.
0
 
LVL 28

Expert Comment

by:sybe
ID: 1209244
You don't really have to do it, but you would like to do it. Because when writing scripts you sometimes want to read the source code in your browser (view source). If you don't do the \n, then the whole result is on one line and very hard to read.

0
 

Expert Comment

by:opsonic
ID: 8159574
alternative solution: you can output

print "hello\r\n";
print "next line";
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question