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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using the "\n";

Status
Not open for further replies.

perlone

Programmer
Joined
May 20, 2001
Messages
438
Location
US
I have a text file called news.txt and it contains the following:

Testing
Testing 2

I want each line display by new line. I used the following:

open(FILE, "news.txt");
@warnings = <FILE>;
close(FILE);

foreach $warnings (@warnings) {
$warns .= &quot;$warnings\n&quot;;
}

When i run it, it shows like this:

Testing Testing 2

But i want it displays like this:

Testing
Testing 2

Any ideas?

I also tried the following but it doesn't work:
foreach $warnings (@warnings) {
$warns .= $warnings;
$warns .= &quot;\n&quot;;
}


 
Since you're probably displaying the result in a browser, it's ignoring the newlines. You need to put a <br> after each line:
Code:
$warns .= &quot;$warnings<br>\n&quot;;
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Thanks a lot. It works really well.
 
You actually don't even need the \n in there at all, but it makes it easier to read if you do a View Source.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top