in reply to Re: Re: Database storage confusion
in thread Database storage confusion

print "What is their name?\n"; my $name = $_; #if ($name ne "") { chomp($name = <STDIN>); $dbm{$name} = ""; print "Added to the list!\n";

should read more like

print "What is their name?\n"; chomp($name = <STDIN>); chomp($number = <STDIN>); $dbm{$name} = $number; print "$name = $dbm{$name} added to the list!\n";

shouldn't it?


---
demerphq


Replies are listed 'Best First'.
Re: Re: Re: Re: Database storage confusion
by sulfericacid (Deacon) on Mar 10, 2003 at 04:11 UTC
    I suppose but I find it easier to write $_ = <STDIN> then assign a variable to hold $_, makes it easier for me to understand or see I guess.

    I already knew how to assign a value to the database key such as your phone number, the thing I'm trying to do is assign more than one value. Ie. I want $number, $address, $city, $emailaddress all stored under $name and have each of them retrievable. I'm reading up on MLDBM since some people yesterday said that would do the trick.

    Thanks for your help!

    "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

      MLDBM does something like a more sophisticated

      # Store $dbm{$name}=join "\0",$number,$address,$citty,$emailaddress; # Fetch my ($number,$address,$citty,$emailaddress)=split /\0/,$dbm{$name};

      Which would perfectly suitable for your limited requirements. (Well, it assumes that there are no \0 in the input data. A safe bet in this situation I think, and easily enforced) But certainly do look into using the module, although for something this simple I wouldnt bother with MLDBM at all. Now if you want to store a sophisticated data structure like a tree or something, then MLDBM gets pulled off the shelf.


      ---
      demerphq