Stamp_Guy has asked for the wisdom of the Perl Monks concerning the following question:

Hello fellow monks. All day I've been trying to figure out a problem I'm having with dbm on my Windows machine. I run the following code and instead of 10001, I get 1212. On the Linux servers I tested it on, it works like a charm. Is this a bug in DBM or something? Below is a test case of what has been causing me grief. If anyone can tell me a way around it, I would be extemely grateful! Thanks!
Stamp_Guy

P.S. For further info on what I've done to test this, please /msg me in the CB. Thanks!

#!/usr/bin/perl -w use strict; my %PL; dbmopen(%PL, "pl", 0777) || die "Can't create DBM: $!"; my $count = 0; while ($count <= 10000) { $PL{$count} = "$count"; $count++; } print "Content-type: text/html\n\n"; print scalar(keys %PL), '/', $count, "\n"; dbmclose(%PL);

Replies are listed 'Best First'.
Re: A major problem/bug with DBM drivers on Windows machines
by chromatic (Archbishop) on Jul 04, 2001 at 03:55 UTC
    Works for me on Linux. What happens if you use tie instead of dbmopen? Or a different DBM module?
    my $count = 10000; my %PL; use DB_File; tie(%PL, 'DB_File', 'pl.dbm', 0777) or die "Can't create DBM: $!"; %PL = map { $_, $_ } ( 0 .. $count ); print scalar(keys %PL), '/', $count, "\n";
Re: A major problem/bug with DBM drivers on Windows machines
by Albannach (Monsignor) on Jul 04, 2001 at 07:15 UTC
    Data from another platform: Win95 / ActiveState v5.6.0 (build 623): 1212/10001  # huh? Ok, this made me want to try Chromatic's code: 10001/10000  # as expected since he did (0..$count)

    Now the interesting thing is I had to install DB_File on This Old Box™ before running Chromatic's version, so just for fun what does Stamp_Guy's code do now? 10001/10001 # aha!

    Now it certainly looks like there was something broken in my first test of Stamp_Guy's code that was fixed in the install. I removed DB_File and sure enough Stamp_Guy's code is borken again. Evidently (and I'm sure there are many here who can explain this) plain old dbmopen defaults to a defective DB that is included with the core ActiveState install. When you install a better one such as that in DB_File, it supersedes the broken one.

    Update: Just to be clear, the first and third results were produced with Stamp_Guy's code unmodified from the root note of this thread. It turns out that Stamp_Guy is using Win98 and I used Win95 for my tests above, but when I repeated the tests on my NT4 box with the same ActiveState Perl build, the correct output appears even without DB_File, so now I suspect an OS problem, and not a problem with the default key+value size limitation in SDBM of 1024 bytes (see perldoc anydbm_file).

    --
    I'd like to be able to assign to an luser

      Data from another platform: Win95 / ActiveState v5.6.0 (build 623): 1212/10001 # huh?
      That "1212/10001" looks correct if you were printing out the hash in scalar context. It basically means "there are 1212 hash buckets that are being used to store 10001 values". Or something similar.

      xoxo,
      Andy
      --
      <megaphone> Throw down the gun and tiara and come out of the float! </megaphone>

Re: A major problem/bug with DBM drivers on Windows machines
by jmcnamara (Monsignor) on Jul 04, 2001 at 14:25 UTC

    In the absence of any other db, perl defaults to using sdbm which is shipped with the core.

    However, the ActiveState version of sdbm for Win98 seems to have been compiled with a *very* small limitation on size. If you increase the size of your data you will get an even smaller number of records:
    $PL{$count} = "$count" x 2;
    Linux and Win2K don't seem to have this problem.

    I guess the solution is to use DB_File, as suggested by Chromatic, or install a real db.

    John.
    --
    <br
Re: A major problem/bug with DBM drivers on Windows machines
by Stamp_Guy (Monk) on Jul 04, 2001 at 03:29 UTC
    Just a side note for clarification: I expected it to output the number of the keys in the database, which should be 10001. Instead I got 1212.
Re: A major problem/bug with DBM drivers on Windows machines
by coolmichael (Deacon) on Jul 04, 2001 at 04:58 UTC
    I didn't get any problems on Win2k with ActivePerl v.5.6.1
    C:\>p.pl Content-type: text/html 10001/10001 C:\>
Re: A major problem/bug with DBM drivers on Windows machines
by myocom (Deacon) on Jul 04, 2001 at 04:14 UTC

    This works as expected (I get 10001) on my Win2K box, running ActivePerl 5.005_03...