Solved

\n does not bring me to a new line

Posted on 1998-08-12
4
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

734 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