Solved

\n does not bring me to a new line

Posted on 1998-08-12
4
148 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
alternative solution: you can output

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now