[comp.lang.perl] DBM help w/perl. Patchlevel 18 and 28

adler@astride..caltech.edu (B. Thomas Adler) (09/28/90)

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               <adler@tybalt.caltech.edu>
<adler@citjulie.bitnet>       <...!ames!elroy!cit-vax!adler>