fromjp has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl #band.cgi - saves data to and removes data from a database #creates appropriate dynamic Web pages print "Content-type: text/html\n\n"; use CGI qw(:standard -debug); use SDBM_File; use Fcntl; #prevent Perl from creating undeclared variables use strict; #declare variables my ($button, $name, $email); #assign values to variables $button = param('Button'); $name = param('Name'); $email = param('Email'); if ($button eq "Put Me On Your Mailing list") { add(); } elsif ($button eq "Remove Me From Your Mailing List") { remove(); } exit; #*****user-defined functions***** sub add { #declare variable my %mail; #open database, add record, close database tie(%mail, "SDBM_File", "maillist", O_CREAT|O_RDWR, 0666) or die "Error opening maillist. $!, stopped"; $mail{$email} = $name; untie(%mail); #create Web page print "<HTML>\n"; print "<HEAD><TITLE>The Jeffrey Sikes Band</TITLE></HEAD>\n"; print "<BODY BGCOLOR=silver>\n"; print "<FONT SIZE=5>\n"; print "<H1>The Jeffrey Sikes Band</H1>\n"; print "Thank you, $name. We will send the monthly \n"; print "newsletter to $email.\n"; print "</FONT></BODY></HTML>\n"; } #end add sub remove { #declare variables my (%mail, $msg); #open database tie(%mail, "SDBM_File", "maillist", O_RDWR, 0) or die "Error opening maillist. $!, stopped"; #determine if user's information is in the database if (exists($mail{$email})) { delete($mail{$email}); $msg = "Thank you, $name. We have removed your "; $msg = $msg . "information from our mailing list."; } else { $msg = "You are not on our mailing list."; } #close database untie(%mail); #create Web page print "<HTML>\n"; print "<HEAD><TITLE>The Jeffrey Sikes Band</TITLE></HEAD>\n"; print "<BODY BGCOLOR=silver>\n"; print "<FONT SIZE=5>\n"; print "<H1>The Jeffrey Sikes Band</H1>\n"; print "$msg\n"; print "</FONT></BODY></HTML>\n"; } #end remove
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: I can't connect to DBM Databases
by naikonta (Curate) on Oct 16, 2007 at 01:44 UTC | |
by fromjp (Initiate) on Oct 16, 2007 at 03:16 UTC | |
by Gangabass (Vicar) on Oct 16, 2007 at 04:17 UTC | |
by fromjp (Initiate) on Oct 17, 2007 at 00:15 UTC | |
by naikonta (Curate) on Oct 18, 2007 at 04:49 UTC | |
|
Re: I can't connect to DBM Databases
by shmem (Chancellor) on Oct 16, 2007 at 05:37 UTC | |
by fromjp (Initiate) on Oct 17, 2007 at 00:24 UTC | |
by shmem (Chancellor) on Oct 22, 2007 at 08:22 UTC | |
by Anonymous Monk on Oct 21, 2007 at 23:23 UTC |