#!/opt/common/bin/perl -w ## This is a small demonstration script to demonstrate the use of ## the CGI module ## Adapted by GDG from the cgi-lib example of ## Steven E. Brenner / cgi-lib@pobox.com. ## ## Time-stamp: ## ## force ourself to declare all variables use strict; ## import the CGI method names we are going to use use CGI qw(:standard); ## Send any errors to the browser use CGI::Carp qw(fatalsToBrowser); my $N="\n"; # two chars instead of four my $owner= 'graham@cs.man.ac.uk'; my $debug=1; # turn debugging on my $query = new CGI; ## Use CGI methods to print HTML headers print + header, $N, start_html(-title => 'Simple CGI Example', -author => $owner, -BGCOLOR => 'white' ), $N, h1('This is output from the example CGI script'); ## Copy values of params into variables. ## Really ought to check that they are all set, but we're ## keeping things simple here. my $name=param('name'); my $quest=param('quest'); my $pet=param('pet'); my $colour=param('colour'); my $message=param('text'); ## Now wrap them up in html to make them appear as we want ## ## make these bold ## $name=strong($name); $quest=strong($quest); $pet=strong($pet); ## change font colour suitably ## $colour= "" . strong($colour) . ""; ## wrap the text up as a preformatted blockquote ## $message=blockquote(pre($message)); ## Build description string ## my @describe=param('describe'); my $description; if (@describe) { for (my $i=0; $i < $#describe -1;$i++) { $describe[$i] .= ","; } $describe[$#describe - 1] .= " and" if ($#describe > 0); $description= strong(join " ", @describe); $description .= "."; if (grep(/witty|intelligent/,@describe) and not grep (/liar/,@describe)) { $description .= " Are you sure you aren't a liar?"; } $description = "

You describe yourself as $description"; } else { $description = "

You seem strangely reluctant to say anything about yourself."; } ## Now print the required output ## print < This is what you have to say for yourself:

$message

ENDOFTEXT ## Now, for debugging purposes, print out a list of all ## the parameters. Control this with var $debug, so we can easily ## switch it off if ($debug) { print + hr, h2("Debug info: Current settings in this form"), $N, $query->Dump, hr; } ## Finish off the html cleanly print end_html, $N; ## That's it.