Hello, I am now learning Perl for two months. Until now, I am doing well. Most of the time, I can solve problems myself just by reading textbook. Now I have a trouble for the first time. I typed exactly what the textbook example shows, but I can not create/open a DBM database. I would like to know why.... I tested from command line, but there were no errors, but no response. Just the prompt appeared.

This is a program that accept the visitor's name and e-mail from an html page, and then store them in a DBM database. Or, if the user wants to remove his/her info from the mailing list, the program remove them. Here is the code:
#!/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

In reply to I can't connect to DBM Databases by fromjp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.