Since my experience with ActiveState is minimal, I would've let someone else
respond. But I never saw another response.
I'm under the impression that DB_File uses legacy libraries of Berkeley
1.86. gdb_file is slightly more up-to-date. But I would recommend either
using the Storable module or BerkeleyDB module. BerkeleyDB, like db_file,
is file based; whereas Storable requires loading and writing the entire
table.
For 3600 name/value pairs, as shown in your example, marshalling an
associative array using Storable is probably sufficient. Storable can also
be applied to a custom object that incorporates your comparator routine.
BerkeleyDB has commercial restrictions in addition to the disadvantage that
its objects are not tied. I've extended BerkeleyDB so that the constructors
return tied objects. My package BerkeleyDB::Lite is available on CPAN
(BerkeleyDB-Lite-1_1.tar.gz). But the implementation is trivial to do the
same thing with ActiveState.
Jim Schueler
On Mon, 26 Sep 2005 06:23:52 -0400, Brendan LeFebvre wrote
> Hello all,
>
> I am having trouble with a DB_File in btree mode. It contains about 3600
> keys.
>
> The script to generate the file is as follows (changed variable
> names to generics for clarity):
>
> --- BEGIN BTREE GENERATOR ---
>
> use warnings;
> use strict;
> use DB_File;
> my %hash = ();
> $DB_BTREE->{'compare'} = \&cmp_casefree;
>
> sub cmp_casefree { my ($a,$b) = @_; lc($a) cmp lc($b) }
> # override default compare function so that, e.g.,
> # "du Pont" will go between "DuO..." and "DuQ..." instead of at the end
>
> tie %hash, "DB_File", "btree.dat", 0777, 0777, $DB_BTREE or die
> "Cannot open file: $!";
>
> $hash{"Key1"} = "Value1";
>
> ... snip ...
>
> $hash{"Key3600"} = "Value3600";
>
> untie %hash;
>
> --- END BTREE GENERATOR ---
>
> OK, now I have a separate script that ties a hash to the file and simply
> iterates through, printing all key-value pairs:
>
> --- BEGIN BTREE READER ---
>
> use strict;
> use DB_File;
> use Fcntl;
>
> # Initialize and load database arrays
>
> my %hash = ();
>
> tie %hash, "DB_File", "btree.dat", 0777, 0777, $DB_BTREE or die
> "Cannot open file: $!"; foreach my $key (keys %hash) { print "$key
> -> $hash{$key}\n"; }; untie %hash;
>
> print "done.\n";
>
> --- END BTREE READER ---
>
> Re-directing the reader's output to a text file and looking it over,
> I see that some of the values are missing.
>
> For instance, where I expect to see:
> Key35 -> Value35
>
> I will instead see:
> Key35 ->
>
> A quick analysis reveals it to be just over 100 values missing out
> of the 3600, some isolated but many in consecutive chunks of approx.
> 5-10 keys.
>
> After re-running the generate script and then the reader script, the
> same values are missing every time. So, while this error is baffling,
> it is at least reproducible, and that comforts me. :)
>
> But here's the interesting part: if I put the reader code at the
> bottom of the generator script-- that is, immediately after making
> the file and untying %hash, I create a new hash %hash2 and tie the
> file to it, then read across all keys-- every value is where it
> should be.
>
> This is ActivePerl 5.8.7 build 813, with DB_File 1.811, both latest
> available at this time, so far as I know. I hope someone can help
> me. Thanks for reading. Let me know if any more information is needed.
>
> BL
--
Open WebMail Project (http://openwebmail.org)
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs