Perl CGI Programming
CGI Example
- The following program displays the obligatory "Hello World"
message to the masses.
#!/usr/bin/perl
use CGI;
use strict;
my $query=new CGI;
# Create a header, and let it default arguments, it likely knows
# better then we do.
print $query->header();
# Start the body of our document, and give it a title (shows up on the
# browser bar and on printouts). All the legal fields within the HTML
# "BODY" tag are supported, and are optional. Other unsupported
# options can be specified as well, and will be correctly added. Note
# that there is nothing actually in the body tag, just HTML modifiers
# being specified.
print $query->start_html({-title=>'The Official Hello World Page',
-author=>'Bill Kilgallon'});
# Now lets create the hello world message in big characters. No
# modifiers, just an argument.
print $query->h1('Hello World (one)!');
# Lets do the same again, but put the World in italics (to show
# nesting) and use an HTML modifier to align it in the center of the
# page
print $query->h1({-align=>'center'}, 'Hello',
$query->em('World'), '(two)!');
# And finally, end the document.
print $query->end_html;
Back to Syllabus
Previous: Paradigms
Next: HTML Elements: Divisions/Paragraphs