I'm losing contents from my database and I'm not sure why. After switching lines around for over the past four hours I'm finally annoyed enough to see if anyone else has a suggestion.

The part we are concerned about is the $sig database and the final if loop on the bottom of the page. After filling out the form and clicking 'save' you get the message saying it's saved and it prints it to screen as assurance. However it doesn't stay in the database, it just disappears and I'm not assigning anything else to it.

I really need to know what I'm doing wrong, this is such a mental strain for me.

#!/usr/bin/perl -w use strict; use warnings; use POSIX; use CGI qw/:standard/; require SDBM_File; my %sig; my $sigsave = "sig.dbm"; my %emails; my $list = "list.dbm"; my $adminmail = "admin\@test.com"; my $sendmail = "/usr/lib/sendmail"; my $signature; tie %emails, 'SDBM_File', $list, O_CREAT | O_RDWR, 0644; if ( !tied %emails ) { print "database unsuccessful $!.\n"; } tie %sig, 'SDBM_File', $sigsave, O_CREAT | O_RDWR, 0644; if ( !tied %sig ) { print "database unsuccessful $!.\n"; } print header, start_html('Email Management'); print "DB contents: $sig{$signature}\n"; print start_form(), table( Tr( td("Subject: "), td( textfield( -name => 'subject', -size => 40 ) ) ), Tr( td("Message: "), td( textarea( -name => 'message', -columns => 40, -rows => 5 ) ) ), Tr( td("Signature: "), td( textarea( -name => 'signature', -default => $sig{$signature}, -columns => 40, -rows => 5 ) ) ), Tr( td( checkbox_group( -name => 'todo', -values => [ 'use', 'save' ], -rows => 2, -columns => 2 ), ), td(submit) ), ), end_form(), hr(); # rid ourselves from those nasty params my $message = param('message'); my $subject = param('subject'); my $signature = param('signature'); my $todo = param('todo'); if ( param() ) { if ( $message && $subject eq "" ) { print "Your subject or email content was missing.\n"; } else { foreach my $key ( keys %emails ) { print "Things we have: $key <br>\n"; } print "<br>\n"; while ( my ( $key, $value ) = each(%emails) ) { # Email Subs, special commands $message =~ s/\[name\]/$value/; #[name] = user name open( MAIL, "| $sendmail -t" ); print MAIL "To: $key\n"; print MAIL "From: $adminmail\n"; print MAIL "Subject: $subject\n\n"; print MAIL "$message\n"; if ( $todo eq "use" && $signature ne "" ) { print MAIL "$signature\n"; } print MAIL ".\n"; close(MAIL); print "Email was sent to: $key !<br>"; } } if ( $todo eq "save" ) { print "<br>"; print "Saving to database<br>\n"; $sig{$signature} = $signature; print "\$sig{\$signature}: $sig{$signature}"; } } untie %emails; untie %sig;

In reply to $var{$var1} = $var1; ? by Anonymous Monk

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.