473,396 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Why is print statement not printing NEW LINE (\n)

135 100+
When I running the following .cgi script, not sure why each print statement is not printing on a new line, even after entering \n. Browser=IE6

See Perl code below:

Expand|Select|Wrap|Line Numbers
  1. #!C:/perl/bin/perl.exe -w
  2.  
  3. print "Content-type:text/html\n\n";
  4.  
  5. use CGI qw(:standard);
  6.  
  7. $name = param('name');
  8. $age = param('age');
  9. $home = param('home');
  10.  
  11. print "NAME: $name\n";
  12. print "HOME: $home\n";
  13. print "AGE:  $age\n";
The output I get is all on one line:
NAME: fred HOME: england AGE: 42
Sep 17 '07 #1
11 28452
KevinADC
4,059 Expert 2GB
it is in the source code, but html has no concept of a newline, you have to use html code to format html pages.
Sep 17 '07 #2
numberwhun
3,509 Expert Mod 2GB
When I running the following .cgi script, not sure why each print statement is not printing on a new line, even after entering \n. Browser=IE6

See Perl code below:

Expand|Select|Wrap|Line Numbers
  1. #!C:/perl/bin/perl.exe -w
  2.  
  3. print "Content-type:text/html\n\n";
  4.  
  5. use CGI qw(:standard);
  6.  
  7. $name = param('name');
  8. $age = param('age');
  9. $home = param('home');
  10.  
  11. print "NAME: $name\n";
  12. print "HOME: $home\n";
  13. print "AGE:  $age\n";
The output I get is all on one line:
NAME: fred HOME: england AGE: 42
I am going to guess that this script is called from another script because I don't see the HTML in here for the form.

Either way, I went and set the variables (all 3) to values, and it printed just fine on 3 different lines.

Not sure why it would be doing that to you.

Regards,

Jeff
Sep 17 '07 #3
KevinADC
4,059 Expert 2GB
He's viewing the output in a browser. He needs to use HTML code to format the output.
Sep 17 '07 #4
numberwhun
3,509 Expert Mod 2GB
He's viewing the output in a browser. He needs to use HTML code to format the output.
he he, silly me. Wasn't thinking along the lines of displaying in the browser.
Sep 17 '07 #5
patelxxx
135 100+
Thank you Kevin, formatting the code with HTML worked. Thanks again.

Kevin, why did the <p> tag before \n did the trick - allow me to print on seperate lines?

i.e.

[CODE:Perl]print "NAME: $name<p>\n";
print "HOME: $home<p>\n";
print "AGE: $age<p>\n";[/code]

Thanks
Sep 17 '07 #6
KevinADC
4,059 Expert 2GB
because <p> means a new paragraph in html code. The browser sees the html tags and formats the display accordingly. The browser completely ignores the newlines.

You will need to learn some basic html coding if you are going to write CGI scripts. HTML is very very easy stuff. There are many online resources that can show you the basics of html code. HTML gets a bit more complicated when you use style sheets, refered to as CSS, but it's still fairly easy stuff.
Sep 17 '07 #7
numberwhun
3,509 Expert Mod 2GB
because <p> means a new paragraph in html code. The browser sees the html tags and formats the display accordingly. The browser completely ignores the newlines.

You will need to learn some basic html coding if you are going to write CGI scripts. HTML is very very easy stuff. There are many online resources that can show you the basics of html code. HTML gets a bit more complicated when you use style sheets, refered to as CSS, but it's still fairly easy stuff.
My recommendation would be to go to w3schools.com. Nothing like learning from those who wrote the spec(s).

Regards,

Jeff
Sep 17 '07 #8
patelxxx
135 100+
Thank you guys for the advise.
Sep 18 '07 #9
add a <br> after each line (i.e. print "NAME: $name\n"; <br> )
Oct 7 '10 #10
Thanks for the help, guys! Now that I've got perl modules under my belt, it looks like I'm only 7 year behind the curve!
Jun 12 '14 #11
No need to use "\n", just use "<br>".
Jun 22 '14 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: entoone | last post by:
print "\t\t<td><bgcolor=#000000><font color=#000000 font color=#000000 face=Tahoma size=2 ><A href='show.php?searchid=$line'>More Info</td>\n"; How would I subsittue text for a graphic in php,...
1
by: Michelle | last post by:
I have tried every variation of the "onchange" statement below without any actual reloading of the page. I am hoping that the PHP PRINT statement is constructed wrong, otherwise it is javaScript...
9
by: François Pinard | last post by:
Hi, people. I hope someone would like to enlighten me. For any application handling Unicode internally, I'm usually careful at properly converting those Unicode strings into 8-bit strings before...
9
by: TY | last post by:
Hi all, I have this little simple script: for i in range(10): for j in range(5000000): pass # Timing-delay loop print i When you run it, it behaves as you would expect -- it prints 0...
3
by: no_spam_for_gman | last post by:
Does db2 have the equivalent of a print statement like SQL server? I wanted to debug a stored procedure I wrote and wanted to output some of the values. I couldn't find it in documentation...The...
12
by: jt2 | last post by:
Hello Perl Gurus! I'm quite a perl neophyte so I'm looking for help understanding why print doesn't print correctly. This may be a totally stupid error.... He is my program. What it is doing...
9
by: TomEhrhorn | last post by:
I wrote some VBA code to create web pages (about 100 "identical" pages) with data from Access tables (data is static). Using "Print #1, ..." is a bit onerous but, with loops for repeated table rows...
2
by: JRough | last post by:
I have this code that switches templates depending on if the user fills in a form with a request. The request asks for the $mark & $number. If that request gets input then it displays a list...
1
by: josh wold | last post by:
Here is my problem. I'm using plink to ssh to devices and pull info off. I need to manipulate this data so that extra 0 at the end is making it difficult. C:\Python30>python PLINKSSHtest.py...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.