Path: utzoo!attcan!uunet!jarthur!nntp-server.caltech.edu!astride!adler From: adler@astride..caltech.edu (B. Thomas Adler) Newsgroups: comp.lang.perl Subject: DBM help w/perl. Patchlevel 18 and 28 Message-ID: Date: 28 Sep 90 00:48:47 GMT Sender: news@nntp-server.caltech.edu Distribution: comp Organization: California Institute of Technology, Pasadena Lines: 50 Nntp-Posting-Host: astride.cs.caltech.edu So I was working on this perl script today, when I noticed that everytime I restarted my program, my dbm arrays were coming up empty. A "strings" on the dbm file showed the data to be there, so I concocted a test program to find out what was going on. This is what I came up with--- --------------------------- #!/usr/bin/perl #dbmopen (TEST, "test", 0600); #$TEST{"mine"} = "abcdef"; #$TEST{5} = 53; #dbmclose(TEST); dbmopen (TEST, "test", 0600)|| print "Failed 1\n"; $TEST{"mine"} = $TEST{"mine"}; # Line no 8. print "TEST = $TEST{mine}\n"; print "KEYS = ", keys(%TEST), "\n"; print "VALUES = ", values(%TEST), "\n"; printf ("TEST = %s\n", $TEST{'mine'}); printf ("TEST = %s\n", $TEST{5}); while (($key, $value) = each %TEST) { print "$key == $value\n"; } dbmclose(TEST) || print "Failed 2\n"; ---------------------------- What I find wierd is that I use the (now) commented lines to setup my assoc array. At this point, all the following print statements print the correct thing. I then commented those lines (and didn't have line no 8.), and suddenly everything was printing blanks, except values from "each", which were correct. I accidentally stumbled onto line 8, at which point every functioned perfectly. Why? Is there something special you have to do to start accessing the dbm file? The first line I tried (in place of line 8) was "undef $TEST{''};", but that ended up defining $TEST{''} to null. (It made everything else work too.) Anybody care to enlighten me? -Bo Adler -- B. Thomas Adler <...!ames!elroy!cit-vax!adler>