Hi glennpm,
Whatever else you do (and a HEREDOC is perfectly fine for generating the HTML, as is Template Toolkit), the one thing you have to do differently with CGI is print headers, followed by at least a single blank line.
For example:
#!/usr/bin/perl
use strict;
use warnings;
# CGI headers (note two newlines, one for a blank line)
print "Content-type: text/html\n\n";
# Now anything else you do is HTML ...
print "<body style='background:cyan'>\n";
print " <center>\n";
print " <h1>Hello world!</h1>\n";
print " </center>\n";
print "</body>\n";
BTW, another style I've gotten in the habit of in place of HEREDOCS is to quote a block of text with qq{ ... }, putting colons ':' at the beginning of each line for visual ease of reading, and finally reformat the text to remove the colons and print it out. For example:
# CGI headers (note two newlines, one for a blank line)
print "Content-type: text/html\n\n";
# Another way to format HTML
my $text = qq{
:<body style="background:cyan">
: <center>
: <h1> Hello world! </1>
: </center>
:</body>
};
output($text);
# Subroutines
sub output {
my ($text) = @_;
# Reformat the HTML text (remove leading colons ':')
$text =~ s/(^\s+:)|((?<=\n)\s+:)|(\s+$)//g;
# And output it
print $text;
}
say
substr+lc crypt(qw $i3 SI$),4,5
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.