I haven't been using perl all that long, but even so it was a head-scratcher deciding which program I should put up here as an example. But I got a hint from Larry Wall, the designer of perl. In his 1998 State of the Onion address he demonstrated his own first CGI script, (newly written!) with the observation that showing off one's first CGI script is to be expected.
Just what I needed to know.
The program that follows was indeed my first CGI script, although it underwent major surgery since it first saw daylight and hardly resembles its original self. Still, it was my first. Originally, it just generated a header and footer with no content; now it shows a fortune cookie from an external program each time it is called. I publish it now with Larry's implicit blessing. ;-)
#!/usr/bin/perl -w
#
#
use strict;
use vars qw( $title $Description $content $boldit $unbold );
$title = "Sample CGI doc";
$Description = "Sample CGI doc description string";
$boldit = "<font=+2><strong>";
$unbold = "</strong></font>";
$content = "<center><i><font size=-1>Quote of the day brought to you with the assistance of perl $].</font></i></center>";
$|= 1;
print STDOUT "Content-Type: text/html\n\n";
print STDOUT '<HTML><HEAD><TITLE>' . "\n";
print STDOUT $title;
print STDOUT '</TITLE>' . "\n";
print STDOUT '<BASE HREF="http://172.1.1.1/index.htm">' . "\n";
print STDOUT '<META NAME="keyword" CONTENT=';
print STDOUT $Description;
print STDOUT '>' . "\n";
print STDOUT '<META NAME="generator" CONTENT="AIX vi--deal with it!">' . "\n";
print STDOUT '</HEAD>' . "\n";
print STDOUT '<BODY BGCOLOR="#FAF0E6" TEXT="#202066" LINK="#0000FF" ALINK="#FF00FF" VLINK="#FF0000">' . "\n";
print STDOUT '';
print STDOUT '<!----Start banner here ----->' . "\n";
print STDOUT '' . "\n";
print STDOUT '<!IMG height="100" width="100" align="top" SRC ="img/Dept.gif" alt="XYZ Development">' . "\n";
print STDOUT '<IMG align="left" SRC ="img/f_logo.gif" alt="Company logo">' . "\n";
print STDOUT '<IMG height="90" width="90" align="right" SRC ="img/icon208.gif" alt="signpost">' . "\n";
print STDOUT '<br>' . "\n";
print STDOUT '<h1><center>' . "\n";
print STDOUT 'XYZ Development' . "\n";
print STDOUT '</h1></center>' . "\n";
print STDOUT '<br>' . "\n";
print STDOUT '<HR align="center" SIZE=4>' . "\n";
print STDOUT '<br>' . "\n";
if ( open INPIPE, "/usr/local/bin/quotes |" ) {
my $i = 0;
print STDOUT $boldit;
print STDOUT '<center>' . "\n";
while (<INPIPE>) {
chomp;
if ( ( /:$/ ) and ( $i == 0 ) ) {
print STDOUT '<i>';
print STDOUT $_;
print STDOUT '</i>';
print STDOUT '<br>' . "\n";
$i++;
} else {
if ( /^--[\w\s]/ ) {
print STDOUT '<br>';
print STDOUT '<font color="blue">';
print STDOUT $_ . '</font><br>' . "\n";
} else {
print STDOUT $_ . '<br>' . "\n";
};
};
};
close INPIPE;
print STDOUT '</center>';
print STDOUT $unbold;
print STDOUT '<p>' . "\n";
};
print STDOUT $boldit;
print STDOUT $content;
print STDOUT $unbold;
print STDOUT '<p>' . "\n";
print STDOUT '<!----The rest of the page ------>' . "\n";
print STDOUT '<br>' . "\n";
print STDOUT '<HR align="center" SIZE=4>' . "\n";
#print STDOUT '<NOSCRIPT>' . "\n";
#print STDOUT '<ADDRESS>A publication of <a href="mailto: bozo\@nowhere.com">XYZ Development</a>' . "\n";
#print STDOUT '</ADDRESS>' . "\n";
#print STDOUT '</NOSCRIPT>' . "\n";
print STDOUT '<SCRIPT LANGUAGE="JavaScript1.1">' . "\n";
print STDOUT '//<!----' . "\n";
print STDOUT 'document.write( "</center><br><ADDRESS>A publication of " );' . "\n";
print STDOUT 'document.write( "<a href=\"mailto: bozo\@nowhere.com\">" );' . "\n";
print STDOUT 'document.write( "XYZ Development</a></ADDRESS>" );' . "\n";
print STDOUT 'document.write( "<br><center>Entered site on " );';
print STDOUT 'document.write( Date() + "<br>" );' . "\n";
print STDOUT 'document.write( "You\'re using " );';
print STDOUT 'document.write( navigator.appName );';
print STDOUT 'document.write( ", version " );';
print STDOUT 'document.write( navigator.appVersion );';
print STDOUT 'document.write( "<br>" );' . "\n";
print STDOUT '//----->' . "\n";
print STDOUT '</SCRIPT>' . "\n";
print STDOUT '<br clear><center><SMALL>Copyright 1998, XYZ Development<br>All rights reserved</SMALL></center>' . "\n";
print STDOUT '</BODY>' . "\n";
print STDOUT '</HTML>' . "\n";