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

I am having troubles settng up an SDBM file. I read the SMALL documenation and it displayed the exention .dbmx, so I used it. But when I execute this, it creates 2 files. name.dbmx.pag and name.dbmx.dir. Are neither of these the database? I am used to using DB_file which created a name.db but I can't get SDBM to work.

No errors or anything, it just won't store my data while converting DB_File scripts to SDBM_File.

my %db; use SDBM_File; my $db = "name.dbmx"; tie %db, "SDBM_File", "$db", O_CREAT | O_RDWR, 0644, or die "Cannot op +en file 'db': $!\n";

Replies are listed 'Best First'.
Re: creating SDBM_File
by matija (Priest) on Mar 08, 2004 at 07:55 UTC
    SDBM creates two files - that is how it works. Both files together make the database. Unless you really, truly, need SDBM for some weird reason, you are much better of using DB_File instead.

    The code you showed doesn't put any data into the array you've just tied, so it's hard to say what is going wrong, but I'd like to draw your attention to this part of the SDBM man page: There are a number of limits on the size of the data that you can store in the SDBM file. The most important is that the length of a key, plus the length of its associated value, may not exceed 1008 bytes.

      I didn't display code because I'm using it as I did with DB_File when it worked. My new webhost told me DB_File does not work with Cpanel, I've tried using the module that they said is installed but it keeps telling me it can't locate DB_File. So that's the reason I'm trying to do this, I don't want to, but I can't access DB_File. Unless anyone has a different module which works very similar to DB_File in the way it comes with Perl and I won't need to change anything except tying the database?
        You can try GDBM_File, or even NDBM_File. See the documentation in AnyDBM_File for a comparison of the different types.

        The code you show looks ok; is the tie actually failing? You don't actually say what isn't working.

Re: creating SDBM_File
by Anonymous Monk on Mar 08, 2004 at 22:22 UTC
    I never heard of such a thing as modules not being able to be used while Cpanel is installed, that seems a little weird to me.