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

R

robertchen117

#!/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:
 
J

J¨¹rgen Exner

#!/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
 
M

Mirco Wahab

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.
 

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

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top