sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:

Still working on the same script but I need a little more help. The problems I'm having don't seem to be fatal anymore, guess that's a step into the right direction, right?

One of the problems is my $dbm{'$unverified'} is overwriting itself, just like the problem in my last SOPW but with a different variable. It only keeps the last value written to it.

The other problem is probably more complex but the error checking isn't functional. At the bottom of the script you will see I am trying to check 2 things: 1) that both url_params exist 2) compare these to the $dbm{'$unverified'} to see if they match. (the testing is at the bottom of the script)

#!/usr/bin/perl -w use strict; use CGI; use POSIX; my $query = CGI->new; my %form = %{$query->Vars}; require SDBM_File; my %dbm; my $dbm_file = "evs.dbm"; my $accountID = $query->url_param('accountID'); my $accountAD = $query->url_param('accountAD'); tie %dbm, 'SDBM_File', $dbm_file, O_CREAT|O_RDWR, 0644; use CGI qw/:standard/; print header, start_html('EVS'), start_form, "What's your email address? ",textfield('usermail'),p, submit, end_form, hr; chomp $form{"usermail"}; my $chars; my $adminmail = "admin\@test.com"; my $sendmail = "/usr/lib/sendmail"; my @chars = ( "A" .. "Z", "a" .. "z", 0 .. 9, qw(! @ $ % ^ & * ) ); my $ID; ### randomize characters do { $ID = join '', map { $chars[ rand @chars ] } 1..17; } while grep {$_ eq $ID} my @used; ### If USERMAIL exists add information to notverified DBM if ($form{'usermail'}) { my @unverified_emails=($form{'usermail'}, $ID); $dbm{'$notverified'}= join "::",@unverified_emails; #foreach my $mail (split /::/, $dbm{'notverified'}) { # print "$mail is not verified!\n"; #} print "An email has been sent to $form{'usermail'}. Please ch +eck it to verify your information.\n"; ### email the users my $accountAD = "$form{'usermail'}"; my $accountID = $ID; open (MAIL, "|$sendmail -t") or die "Cannot access mail"; print MAIL "To: $form{'usermail'}\n"; print MAIL "From: $adminmail\n"; print MAIL "Subject: Verify your Email Address\n\n"; print MAIL "http://sulfericacid.perlmonk.org/evs/evs.pl?accountID=$a +ccountID&accountAD=$accountAD\n"; close (MAIL); } ### If url_param() exists if ($accountID && $accountAD) { &params; } ### If url_param() exists check to see if it exists in DBM sub params { if ($accountID && ($accountAD ne '') && (exists $dbm{'$notverified'})) + { $dbm{'$verified'} = $accountAD; print "Your address has been indexed!\n"; ### test database prints foreach (sort keys(%dbm)) { print "$_ => $dbm{$_}\n"; } } else { print "Your email address and registration did not match. Please ch +eck your email again.\n"; } }


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re: Database still overwriting itself
by Mr. Muskrat (Canon) on Feb 14, 2003 at 18:26 UTC
    One thing stands out...
    $dbm{'$unverified'} is not the same as $dbm{$unverified}

    Try this:

    my $unverified = 'this'; my %dbm = ( this => 'bar', ); print $dbm{$unverified},$/; print $dbm{'$unverified'},$/;
Re: Database still overwriting itself
by l2kashe (Deacon) on Feb 14, 2003 at 20:04 UTC
    NIT
    You still aren't die'ing or warn'ing if you fail to tie your DBM file
    /NIT

    /* And the Creator, against his better judgement, wrote man.c */
Re: Database still overwriting itself
by jasonk (Parson) on Feb 14, 2003 at 18:22 UTC

    The single quotes are preventing variable expansion, so your database only contains one key, with the word '$notverified' in it. Inside single quotes a $ doesn't mean anything except dollars. Use $dbm{$notverified} instead.

      I tried removing the single quotes but it creates an internal server error saying the line with $dbm{$notverified} needs a global symbol. I try to my it but it says that's incorrect syntax.

      Any suggestions?

      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid
        After looking through your code a little more thoroughly, I see that $notverified and $verified are never defined. So if you remove the single quotes, you get an error. If you leave them, you are creating the keys named for your variables. And don't get me started on your logic behind this...
Re: Database still overwriting itself
by sulfericacid (Deacon) on Feb 16, 2003 at 05:28 UTC
    Ok, I'm testing to see if the tie was successful or not. The current script is below and there isn't a problem, the database is successful at that point. Any other suggestions?

    #!/usr/bin/perl -w use strict; use CGI; use POSIX; my $query = CGI->new; my %form = %{$query->Vars}; require SDBM_File; my %dbm; my $dbm_file = "evs.dbm"; my $accountID = $query->url_param('accountID'); my $accountAD = $query->url_param('accountAD'); tie %dbm, 'SDBM_File', $dbm_file, O_CREAT|O_RDWR, 0644; if (!tied %dbm) { print "database unsuccessful.\n"; } use CGI qw/:standard/; print header, start_html('EVS'), start_form, "What's your email address? ",textfield('usermail'),p, submit, end_form, hr; chomp $form{"usermail"}; my $chars; my $adminmail = "admin\@test.com"; my $sendmail = "/usr/lib/sendmail"; my @chars = ( "A" .. "Z", "a" .. "z", 0 .. 9, qw(! @ $ % ^ & * ) ); my $ID; ### randomize characters do { $ID = join '', map { $chars[ rand @chars ] } 1..17; } while grep {$_ eq $ID} my @used; ### If USERMAIL exists add information to notverified DBM if ($form{'usermail'}) { my @unverified_emails=($form{'usermail'}, $ID); $dbm{'$notverified'}= join "::",@unverified_emails; #foreach my $mail (split /::/, $dbm{'notverified'}) { # print "$mail is not verified!\n"; #} print "An email has been sent to $form{'usermail'}. Please ch +eck it to verify your information.\n"; ### email the users my $accountAD = "$form{'usermail'}"; my $accountID = $ID; open (MAIL, "|$sendmail -t") or die "Cannot access mail"; print MAIL "To: $form{'usermail'}\n"; print MAIL "From: $adminmail\n"; print MAIL "Subject: Verify your Email Address\n\n"; print MAIL "http://sulfericacid.perlmonk.org/evs/evs.pl?accountID=$a +ccountID&accountAD=$accountAD\n"; close (MAIL); } ### If url_param() exists if ($accountID && $accountAD) { &params; } ### If url_param() exists check to see if it exists in DBM sub params { if ($accountID && ($accountAD ne '') && (exists $dbm{'$notverified'})) + { $dbm{'$verified'} = $accountAD; print "Your address has been indexed!\n"; ### test database prints foreach (sort keys(%dbm)) { print "$_ => $dbm{$_}\n"; } } else { print "Your email address and registration did not match. Please ch +eck your email again.\n"; } }


    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid