- Example 1. Here is the form that tests this
example. Below is the cgi script file used in the example:
#!/usr/bin/perl
use CGI param,header,p,b,start_html,end_html;
$name = param("your name");
$food = param("food");
print header();
print start_html();
print p("Hi $name!");
print p();
print b("Would you like some $food?");
print end_html();
You can also handle the same form using POST
method
- A bit more advanced version of the same example. Click here for the form (includes the form
validation, needs to be changed so that it works in IE).. The script
for that example (slightly different from the one above) is here:
#!/usr/bin/perl -w
use CGI param,header,p,b,start_html,end_html;
$name = param("yourname");
$food = param("food");
$broccoli = param("broccoli");
print header();
print start_html();
print p("Hi $name!");
print p();
print b("Would you like some $food?");
if ($broccoli eq "cantstandit") {
print p("No broccoli for you");
}
elsif ($broccoli eq "notcrazy") {
print p("Have a bit of broccoli first");
}
else {
print p("Here is a huge plate of broccoli for you!");
}
#print p("$broccoli");
print end_html();
- This perl program creates a small database with one entry indexed
by the key 'key1' the first time it runs
(it creates two files mydbm.dir and mydbm.pag). On subsequent runs the
program updates the database.
#!/usr/bin/perl -w
dbmopen (%data, "mydbm", 0666) || die "can not open the database file";
$data{'key1'} = $data{'key1'} + 1;
print "$data{'key1'}\n";