\n not working on windows server

D

dextergirl67

I am just starting out with Perl scripts running on a Windows Server
2003, but the \n newline is not working. The output appears on one
line. Here is my short code and does anyone know why the \n is not
working?

#!/usr/bin/perl
print "Content-Type: text/html\n\n";
use CGI ':standard';
print "Hello World!.\n\n";
print "How are You?.";
 
G

Gunnar Hjalmarsson

I am just starting out with Perl scripts running on a Windows Server
2003, but the \n newline is not working. The output appears on one
line. Here is my short code and does anyone know why the \n is not
working?

#!/usr/bin/perl
print "Content-Type: text/html\n\n";
use CGI ':standard';
print "Hello World!.\n\n";
print "How are You?.";

The \n is probably working just fine. It's just that the script tells
the browser that HTML is sent, and newlines are displayed as spaces in
HTML. Either you can print <br> tags, or you can tell the browser that
the script is sending plain text:

print "Content-Type: text/plain\n\n";

Btw, why are you using CGI when you aren't using it?
 
A

A. Sinan Unur

(e-mail address removed) wrote in @z14g2000cwz.googlegroups.com:
I am just starting out with Perl scripts running on a Windows Server
2003, but the \n newline is not working. The output appears on one
line. Here is my short code and does anyone know why the \n is not
working?

#!/usr/bin/perl
print "Content-Type: text/html\n\n";

Why are you lying about the content type?
use CGI ':standard';
print "Hello World!.\n\n";
print "How are You?.";

If you use CGI, you should use CGI.

Sinan
 
D

dextergirl67

Thanks for help, but it is still not working correctly. I changed my
code a bit, ran it and this time it only output the string in the first
print statement and it ignored the other print statement...Strange?

#!/usr/bin/perl
print "Content-Type: text/plain\n\n";
print "Steady plodding brings prosperity to all.\n";
print "Hasty speculation leads to poverty.";
 
D

dextergirl67

I have gotten extremely frustrated with Perl on our Windows 2003
Server.
1. I ran this code on our server:
use CGI ':standard';
print "Hello World!.\n\n";
print "How are You?.";

2. The output is a blank white screen in the browser and when I do a
view source on that page I see this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html;
charset=windows-1252"></HEAD>
<BODY></BODY></HTML>

3. Last this script ran fine on our windows server, but with the new
Windows 2003 server the code will not work and I do not know why. I
suspect it is not configured properly, but that is not my job, but if
so I would like to be able to suggest to them how to fix Perl. Thanks
for the help....
 
D

dextergirl67

With your help and a few experiments, I got it to work like this:

#! /usr/bin/perl
print "Content-type: text/plain\n";
print "\n";
print "Hello\n";
print "Good bye";


Thank You!
 
S

Scott Bryce

I have gotten extremely frustrated with Perl on our Windows 2003
Server.
1. I ran this code on our server:
use CGI ':standard';
print "Hello World!.\n\n";
print "How are You?.";

2. The output is a blank white screen in the browser

This has nothing to do with Perl or your server configuration.

You are not sending any http headers to the browser. When the browser
receives the first line of text, followed by a blank line, it thinks
that that is the http header. There is nothing in that "header" that
explains what the browser is supposed to do with the remaining text.

You really need to learn how http works, but that is a topic for another
newsgroup.

BTW, as someone else has pointed out, there is no reason to use CGI, if
you are not going to use it.
 
S

Scott Bryce

Thanks for help, but it is still not working correctly. I changed my
code a bit, ran it and this time it only output the string in the first
print statement and it ignored the other print statement...Strange?

#!/usr/bin/perl
print "Content-Type: text/plain\n\n";
print "Steady plodding brings prosperity to all.\n";
print "Hasty speculation leads to poverty.";

use strict;
use warnings;

# Tell Perl not to buffer output
$|= 1;

print "Content-Type: text/plain; charset=iso-8859-1\n\n";
print "Steady plodding brings prosperity to all.\n";
print "Hasty speculation leads to poverty.";
 
J

Jürgen Exner

I am just starting out with Perl scripts running on a Windows Server
2003, but the \n newline is not working. The output appears on one
line. Here is my short code and does anyone know why the \n is not
working?

#!/usr/bin/perl
print "Content-Type: text/html\n\n";
use CGI ':standard';
print "Hello World!.\n\n";
print "How are You?.";

Can't repro, your program prints beautiful newlines here:

C:\tmp>t.pl
Content-Type: text/html

Hello World!.

How are You?.
C:\tmp>

Your Perl program is working fine, but maybe you are looking at the wrong
place?

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top