\n not working on windows server

Discussion in 'Perl Misc' started by dextergirl67@yahoo.com, Oct 7, 2005.

  1. Guest

    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?.";
     
    , Oct 7, 2005
    #1
    1. Advertising

  2. wrote:
    > 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?

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Oct 7, 2005
    #2
    1. Advertising

  3. 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 <>
    (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
     
    A. Sinan Unur, Oct 7, 2005
    #3
  4. Guest

    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.";
     
    , Oct 7, 2005
    #4
  5. Guest

    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....
     
    , Oct 7, 2005
    #5
  6. Guest

    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!
     
    , Oct 7, 2005
    #6
  7. Scott Bryce Guest

    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, Oct 7, 2005
    #7
  8. Scott Bryce Guest

    wrote:
    > 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.";
     
    Scott Bryce, Oct 7, 2005
    #8
  9. wrote:
    > 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
     
    Jürgen Exner, Oct 11, 2005
    #9
  10. <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 11, 2005
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Rattz
    Replies:
    3
    Views:
    451
    Scott Allen
    Jun 15, 2005
  2. Luqman
    Replies:
    1
    Views:
    725
    Juan T. Llibre
    Jun 29, 2005
  3. gaurav tyagi
    Replies:
    14
    Views:
    1,373
    gaurav tyagi
    Jan 20, 2006
  4. Replies:
    0
    Views:
    884
  5. Replies:
    0
    Views:
    355
Loading...

Share This Page