in reply to Database issues

Is $this a constant? If it isn't, than there's your answer.

Keep in mind, if you're using a key that is a variable, it will change at any given point throughout the program as you redefine what $this is. When you call it, you can really only say it's getting over-written if $this is constant and never changing.

#/!usr/bin/perl use strict; my $this = "key1"; my $that = "in1"; $hashname{$this} = $that; # $hashname{'key1'} is 'in1' $this = "key2"; $that = "in2"; $hashname{$this} = $that; # $hashname{'key2'} is 'in2' # $hashname{'key1'} is still 'in1' # eof
Also note that if you're doing some test down the line, if $that is a string, make sure you're using the text operators (eq, for example) as opposed to the numerical operators (==, !=, etc).

Without a better description of your problem, or at least a code snippet, I'm not sure you're going to get the 100% answer you're looking for.

--Coplan

Replies are listed 'Best First'.
Re: Re: Database issues
by Anonymous Monk on Apr 09, 2003 at 16:27 UTC
    Snippet:
    # have a db and hash $stats open # form is incomplete in the snippet but you get the general idea # print "Name: " textfield( -name => 'name', -size => 100); print "age: " textfield( -name => 'name', -size => 5); my $name = param('name'); my $age = param('age'); #store every person from the form into the database $stats{$name} = $age;
      ... print "age: " textfield( -name => 'age', -size => 5); ...

      -derby

      Regardless of what you print beside it the form item has a value called name. You set them both to be 'name'. When you submit the form with

      Name: [ george ] Age: [ 6 ]


      when using a GET type request, note that the cgi will be appended with ?name=george&name=6.

      This describes the parameters, and in fact, the outcome is that there is no parameter named 'age'. your fix is this:
      print "age: " textfield ( -name => 'age', -size => 5);


      -nuffin
      zz zZ Z Z #!perl
        Ok, I am getting so frustrated now. I removed the scalar as a key and just put 'name' as a test ($stats{'name'} = $name) but even THAT only stores on value at a time! Can someone tell me why?
        I did your latest suggestion putting it back as a scalar but it DOESN'T change anything! Whether i use 'email' or $email (the latter should be dynamic so they can't over write eachother) I get the same result.
        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"; }