Re: macperl-webcgi Digest 17 Oct 2001 14:35:23 -0000 Issue 35
[email protected] ("Steve Driver") Wed, 17 Oct 2001 11:30:20 -0400
| Newsgroups | perl.macperl.webcgi |
|---|---|
| Message-ID | <[email protected]> |
While this shouldn't matter on the Mac, the dbmopen command normally adds the proper extension to the end of the db file's name (I've seen .pag, .dir, .db). Try eliminating the .dbm extension when you define $dbName. (from the "Programming Perl" book) dbmopen ASSOC,DBNAME,MODE [This function has been superseded by the tie() function.] This binds a dbm(3) or ndbm(3) file to an associative array. ASSOC is the name of the associative array. (Unlike normal open, the first argument is NOT a filehandle, even though it looks like one). DBNAME is the name of the database (without the .dir or .pag extension). If the database does not exist, it is created with protection specified by MODE (as modified by the umask() ). If your system only supports the older DBM functions, you may perform only one dbmopen() in your program. If your system has neither DBM nor ndbm, calling dbmopen() produces a fatal error. ----- Original Message ----- Message-ID: <[email protected]> Date: Wed, 17 Oct 2001 15:32:48 +0100 From: "Stephen Criddle" <[email protected]> MIME-Version: 1.0 To: [email protected] Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Simple database in MacPerl I've been trying to use DBM files (as documented in the O'Reilly Perl Cookbook) using DB_File and the dbmopen command, then accessing the data as a normal hash. I just can't seem to get this to work under MacPerl (even though the lib files are there). MacPerl keeps locking up, or not updating the has properly when I try to run even a simple program. For instance: #!perl use DB_File; $dbName = "testdb.db"; dbmopen %dbHASH, $dbName, 0666 or die "Can't open DB File"; $dbHASH{"Steve"}++; print $dbHASH{"Steve"}."\n"; $dbHASH{"Steve"}++; print $dbHASH{"Steve"}."\n"; dbmclose %dbHASH; When I first run this, the testdb.db file is created successfully. However, the output when the program is either: 1 1 or 1 <MacPerl locks up> Am I doing something wrong here? (Trying to use DB_File, perhaps?) Or is there a simple alternative for what I'm trying to do. I really don't want to get bogged down in using SQL if I can help it, since all I'm trying to do is create a lookup table based on a key value. Since the file number of keys might get quite large (IP addresses on an intranet), I wanted to use a hash rather than hunting through a text file for the value I'm after). Steve Criddle