473,231 Members | 1,937 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,231 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 28415
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.