From: zentara <[EMAIL PROTECTED]>
> I'm starting to look at perl db's, and I ran across
> something, but I'm not sure what it's about.
> I have questions.
>
> In the below code, if I comment out "use DB_File";
> I get an unsorted printout, and only 2 files are
> created, dbmdatabase.dir and dbmdatabase.pag.
> Everything seems fine.
>
> If I leave "use DB_File" in, I get back a sorted
> printout, and 3 files are produced, the above mentioned
> 2, and plain dbmdatabase.
>
> So, is it acceptable to use db without "use DB_File";
> or if I do use it, can I always count on the automatic
> sorting? The docs seem to say that hashes will come back
> unsorted without a sort routine.
>
>
> #############################################################
> #!/usr/bin/perl
> use warnings;
> use strict;
> use DB_File;
>
> my (%Z,$i,$j);
> dbmopen(%Z,"dbmdatabase",0644)
> || die "cannot open DBM dbmdatabase: $!";
The dbmopen/dbmclose functions are kind of obsolete. It's generaly
better to use the tie() interface.
Anyway in your case the "use DB_File" statement replaced the
"builtin" DBM implementation by Berkeley DB implemented (OK,
interfaced) via the DB_File module. I'm not sure what exactly are
the properties of the "builtin" DBM code, but I bet Berkeley will be
better. But you will want to use
tie %hash, 'DB_File', $filename, $flags, $mode, $DB_HASH ;
instead of dbmopen() since that will allow you more control over the
options.
Jenda
=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
--- me
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]