Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

\n not working on windows server

1 view
Skip to first unread message

dexter...@yahoo.com

unread,
Oct 6, 2005, 10:43:54 PM10/6/05
to
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?.";

Gunnar Hjalmarsson

unread,
Oct 6, 2005, 10:58:24 PM10/6/05
to

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?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

A. Sinan Unur

unread,
Oct 6, 2005, 11:04:44 PM10/6/05
to
dexter...@yahoo.com wrote in news:1128653034.810797.89370
@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

--
A. Sinan Unur <1u...@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

dexter...@yahoo.com

unread,
Oct 6, 2005, 11:05:12 PM10/6/05
to
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.";

dexter...@yahoo.com

unread,
Oct 6, 2005, 11:17:50 PM10/6/05
to
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....

dexter...@yahoo.com

unread,
Oct 6, 2005, 11:40:39 PM10/6/05
to
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!

Scott Bryce

unread,
Oct 6, 2005, 11:49:55 PM10/6/05
to
dexter...@yahoo.com wrote:

> 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.

Scott Bryce

unread,
Oct 7, 2005, 12:28:04 AM10/7/05
to

use strict;
use warnings;

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

print "Content-Type: text/plain; charset=iso-8859-1\n\n";

Jürgen Exner

unread,
Oct 11, 2005, 10:52:50 AM10/11/05
to

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


Tad McClellan

unread,
Oct 11, 2005, 1:53:10 PM10/11/05
to
dexter...@yahoo.com <dexter...@yahoo.com> wrote:

> The output appears on one
> line.

> print "Content-Type: text/html\n\n";

[ snip]

> print "Hello World!.\n\n";


That looks like text/plain not the text/html that your code
promised it would be...


--
Tad McClellan SGML consulting
ta...@augustmail.com Perl programming
Fort Worth, Texas

0 new messages