CGI Perl Scripts
#!/usr/bin/perl -wT
 
use strict;
use CGI qw/:standard/;  #CGI.pm also provides the param() function
 
# ---
# cgi support functions (put in a .pm file?)
 
sub cgi_html_header_start
{
   # Outputs the start of the HTML document being generated.
   # Includes required "Content-type" for the web server,
   #    opening comments, <html> tag, <head> tag.
 
   print "Content-type: text/html\n\n";   # or text/xhmtl?
 
   print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n";
   print " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
   print "\n";
   print "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
   print "\n";
   print "<head>\n";
   print "\n";
 
   return;
}
 
sub cgi_html_title
{
   my ($browser_title) = @_;
 
   if ( not defined $browser_title || $browser_title eq q// )
   {
      $browser_title = "Untitled Page";
   }
 
   print "<title>\n";
   print "   $browser_title\n";
   print "</title>\n";
   print "\n";
 
   return;
}
 
sub cgi_html_link_css
{
   my ($css_file) = @_;
 
   if ( defined $css_file && $css_file ne q// )
   {
      print "<!-- Include CSS file -->\n";
      print "<link href=\"$css_file\" rel=\"stylesheet\" type=\"text/css\" />\n\n";
   }
 
   return;
}
 
sub cgi_html_header_end
{
   print "</head>\n\n";
   return;
}
 
sub cgi_html_body_start
{
   print "<body id=\"std-body\">\n";  # "std-body" is my CSS ID for the standard body tag
   return;
}
 
sub cgi_html_end
{
   print "</body>\n</html>\n";
   return;
}
 
# ---

Using param()
use CGI qw/:standard/;  #CGI.pm also provides the param() function
$myParm = param('xyz');
if ( not defined $myParm )
{
   # Handle missing parameter xyz
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License