Solved

\n does not bring me to a new line

Posted on 1998-08-12
4
188 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Six Sigma Control Plans

634 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