CGI why ignore "\n", no return, no new line?

Discussion in 'Perl Misc' started by robertchen117@gmail.com, Feb 6, 2007.

  1. Guest

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


    $no_connected = 0;
    $no_unkown = 0;
    $no_unreachable = 0;
    $no_disconnected= 0;
    $no_unavailable= 0;
    $total = 0;
    $others = 0;

    printf("-----------------------------------------------------------------------
    \n");
    printf("%s total hosts\n", $total);
    printf("%6s hosts connected\n", $no_connected);
    printf("%6s hosts unreachable\n", $no_unreachable);
    printf("%6s hosts unkown\n", $no_unkown);
    printf("%6s hosts disconnected\n", $no_disconnected);
    printf("%6s hosts unavailable\n", $no_unavailable);
    printf("%6s hosts others status\n", $others);
    printf("-----------------------------------------------------------------------
    \n");


    put in my apache, and access the cgi, the result is:
    -----------------------------------------------------------------------
    0 total hosts 0 hosts connected 0 hosts unreachable 0 hosts unkown 0
    hosts disconnected 0 hosts unavailable 0 hosts others status
    --------------------------------------------------------------
    ---------

    my question is: why no new return? no new line?
     
    , Feb 6, 2007
    #1
    1. Advertising

  2. wrote:
    > #!/usr/bin/perl
    > use CGI;
    > print "Content-type: text/html\n\n";

    [...]
    > printf("-----------------------------------------------------------------------
    > \n");
    > printf("%s total hosts\n", $total);


    This output doesn't look like HTML to me. Why are you lying about the
    content type?

    > put in my apache, and access the cgi, the result is:
    > my question is: why no new return? no new line?


    Because HTML is a free format markup language.

    Of course this has nothing to do with Perl in the first place anyway.

    jue
     
    J¨¹rgen Exner, Feb 6, 2007
    #2
    1. Advertising

  3. Mirco Wahab Guest

    wrote:

    > use CGI;
    > print "Content-type: text/html\n\n";


    (!)

    > printf("%s total hosts\n", $total);
    > printf("%6s hosts connected\n", $no_connected);


    (!)

    > my question is: why no new return? no new line?


    As Sherm & Juergen said, there's nothing
    like a "\n" in HTML that modifies the
    layout.

    BTW you aren't using any part of
    the module included by 'use CGI',

    this module provides some functionality
    that translates the program flow into
    structural markup and markup-bound layout
    instructions compatible with older HTML
    concepts.

    Your example would have looked in the
    good old times of pre-XHTML like this ...


    #!/usr/bin/perl
    use CGI qw':standard';

    $no_connected = 0;
    $no_unkown = 0;
    $no_unreachable = 0;
    $no_disconnected = 0;
    $no_unavailable = 0;
    $total = 0;
    $others = 0;

    print
    header, start_html('chens site'),
    hr,
    table( {-border=>"0"},
    Tr(
    [
    td([ $total, 'total hosts' ]),
    td([ $no_connected , 'hosts connected' ]),
    td([ $no_connected , 'hosts connected' ]),
    td([ $no_unreachable, 'hosts unreachable' ]),
    td([ $no_unkown, 'hosts unkown' ]),
    td([ $no_disconnected,'hosts disconnected' ]),
    td([ $no_unavailable, 'hosts unavailable' ]),
    td([ $others, 'hosts others status'])
    ]
    )
    ),
    hr,
    end_html;


    .... which would result in a somehow proper table-markup
    (which matches your intention more or less).

    Regards

    M.
     
    Mirco Wahab, Feb 6, 2007
    #3
    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. Dave Tichenor
    Replies:
    3
    Views:
    32,146
    Steven Cheng[MSFT]
    Feb 17, 2004
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,003
    Smokey Grindel
    Dec 2, 2006
  3. Andreas Leitgeb
    Replies:
    0
    Views:
    453
    Andreas Leitgeb
    May 15, 2009
  4. Rob Meade
    Replies:
    6
    Views:
    270
    Rob Meade
    Mar 1, 2004
  5. ngoc

    ignore new line for long string

    ngoc, Aug 8, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    124
    Anno Siegel
    Aug 9, 2005
Loading...

Share This Page