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

Hi, I'm having issues with MLDBM. Here is the code snippet followed by the error:

tie(%positions_hash, 'MLDBM', 'positions.db', O_CREAT|O_RDWR, 0640) or die "Could not create db file\n";

Error: MLDBM error: Second level tie failed, "No such file or directory"

Here is the start of the file where I load modules:
use Fcntl qw(O_RDWR O_CREAT); use MLDBM qw(DB_File Storable); use File::Temp; use Data::Dumper;
I'm pretty sure this is not a permissions issue since I have write access to the directory. Can anyone help?

Thanks greigite

Replies are listed 'Best First'.
Re: MLDBM tie fails
by oko1 (Deacon) on Dec 16, 2008 at 23:38 UTC

    You don't show the rest of your code (i.e., the 'use' statements and the other necessary modules); I suspect that this is where the failure is coming from. Example of working code:

    #!/usr/bin/perl -w use strict; use Fcntl; use MLDBM qw/DB_File Storable/; tie my %positions_hash, 'MLDBM', 'positions.db', O_CREAT|O_RDWR, 0640 +or die "positions.db: $!\n"; %positions_hash = ( foo => 1, bar => 2, qux => 3, ); untie %positions_hash;

    On my system (Ubuntu Linux, AMD64), this creates three files - 'positions.db{,dir,pag}' - exactly as expected.


    --
    "Language shapes the way we think, and determines what we can think about."
    -- B. L. Whorf
      Thanks for your response. I included the use statements at the top of my post. Sorry, but I don't understand how these are incorrect- can you specify? They look quite similar to yours. Here is the relevant code in my program:
      #!/usr/bin/perl -w use strict; use Fcntl qw(O_RDWR O_CREAT); use MLDBM qw(DB_File Storable); .... tie(%positions_hash, 'MLDBM', 'positions.db', O_CREAT|O_RDWR, 0640) or + die "Could not create db file\n"; #write positions hash to db file untie %positions_hash;

      The hash is a large, complex multi-level structure created in several subroutines which I didn't post. I suspect the problem has something to do with its size (> 1G). Your code, which is basically identical to mine except that the tied hash is a single-level small structure, also works fine on my system.

        I don't recall seeing them in your original post; did I just miss them, or did you do a "stealth" update? In any case, given that additional datum, my response would be the same as tilly's: MLDBM is reputed to suffer "mysterious failures" when stressed (I tend to avoid it, myself.) Again, echoing tilly, DBM::Deep is a good recommendation.


        --
        "Language shapes the way we think, and determines what we can think about."
        -- B. L. Whorf