"\n" Does not start a new line
What is wrong with this small script? When I run it in the Run Window, it prints everything on one long line. I am new to Perl but I thought that "\n" at the end of a line would start a new line.
#!/usr/local/bin/perl -w
use CGI qw(:all);
print header;
print "Why is all this on one line?\n";
print "\n";
print "The third Line.\n";
print "The fourth line.\nThe fifth line.\n";
print "The sixth line.\nThe seventh line.\n";
Answer:
The new lines are printed! However when the browser parses the page and displays it using the html standard, new lines are not the \n character but instead the "<br>" tag. So add <br> at the end of each line, like:
print "The third Line.<br>";
You can also add the \n but this is optional. Adding the \n would make a difference only if someone selected "view source" while viewing the page in internet explorer, or if you select the "text" tab in optiperl.
24.11.2002. 06:22
This article hasn't been commented yet.
Write a comment