473,545 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

135 New Member
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 28480
KevinADC
4,059 Recognized Expert Specialist
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 Recognized Expert Moderator Specialist
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 Recognized Expert Specialist
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 Recognized Expert Moderator Specialist
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 New Member
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 Recognized Expert Specialist
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 Recognized Expert Moderator Specialist
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 New Member
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

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

Similar topics

1
3052
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, using a print statement? I'm trying to have a graphic be inserted in place of the More Info text. The graphic name is 2.gif
1
5158
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 error an needs to be posted in the javaScript newsgroup. The FireFox javaScript Console reports the following message: Error: missing : in...
9
2298
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 writing them out. However, this morning, I mistakenly forgot to do so before using one Unicode string (containing a non-ASCII character) as an...
9
1522
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 <pause> on the next line prints 1 <pause> on the next line prints 2 <pause>
3
11246
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 only thing that looked close was signal statement.
12
1906
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 is parsing a file of comma seperated values and trying to extract the address field every time the clock field transitions from a zero to a one. ...
9
4918
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 was not too bad. However, I did find one problem for which I have no solution. In certain conditions (100% repeatable within a group of data but not...
2
2166
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 otherwise it re-displays the form request. The $template variable changes the value of which template is displayed. if($mark&&$num){ $mark = $mark =...
1
2426
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 Enter your username: josh Password: plink -pw nowayjose -ssh nope@1.1.1.1 "show run | inc hostname" hostname net-R2 0 <------------MY ISSUE
0
7409
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7664
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7921
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7771
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1900
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.