in reply to Re: Re: Re: Database issues
in thread Database issues

This same code does the exact same as using a scalar as the key, it only saves one thing. This is using the method $hash{this} = $that now and still it's screwing something up. rrrr, this isn't fun anymore!
print start_form(), table( Tr( td("Name: "), td( textfield( -name => 'name', -size => 40 ) ) ), Tr( td("Email: "), td( textfield( -name => 'email', -size => 40 ) ) ), Tr( td(), td(submit) ), ), end_form(), hr(); if ( param() ) { my $email = param('email'); my $name = param('name'); if ( param('email') ne "" ) { tie %this, 'SDBM_File', $list, O_CREAT | O_RDWR, 0644; if ( !tied %this ) { warn("database unsuccessful $!.\n"); } ################# Next line ethis{'email'} = "$name"; }

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Database issues
by nothingmuch (Priest) on Apr 09, 2003 at 18:18 UTC
    This is the structure of the hash you want:
    %hash = ( # george is added 'george@host.com' => 'george', ); %hash = ( # bill is added 'george@host.com' => 'george', 'bill@company.net' => 'bill', );
    But you're not setting with the actual value of the email field that has been passed. You're setting the key to the value 'email', instead of an email address, thus producing
    %hash = ( # george is added 'email' => 'george', ); %hash = ( # bill is added 'email' => 'bill', );
    The outcome is that they're names are overwritten, because you're accessing the field by the same key, which is 'email', instead of $email, they're addresses.

    Your fix is:
    $this{$email} = $name;


    -nuffin
    zz zZ Z Z #!perl