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

All, I'm trying to get some data out of an old file that was stored with mod MLDBM. When the file was created (about 5 years ago), the module was invoked like so: use MLDBM "DB_File"; but apparently the module has been updated since then because that is no longer a method it exports, and when I try to use it I'm told it can't find package DB_File.pm

So I tried to use it with the currently supported invocations. With just use MLDBM; I get error "Argument "2.121_08" isn't numeric in subroutine entry at C:/Perl/site/lib/MLDBM/Serializer/Data/Dumper.pm line 5 Usage: SDBM_File::TIEHASH(dbtype, filename, flags, mode) at C:/Perl/site/lib/MLDBM.pm line 143." And using use MLDBM qw(SDBM_File Storable); yields error: "Usage: SDBM_File::TIEHASH(dbtype, filename, flags, mode) at C:/Perl/site/lib/MLDBM.pm line 143."

Anybody know how I can strighten this out?

Thanks......Steve

Replies are listed 'Best First'.
Re: MLDMB Problem
by graff (Chancellor) on Aug 09, 2008 at 15:46 UTC
    In the five years since that data file was created, have you moved to a different machine where DB_File is not installed yet? You don't mention anything that indicates whether DB_File (a separate module relative to MLDBM) is currently installed on the machine you are using now. If DB_File.pm isn't installed yet, that is the problem.
      Ah, right you are. I thought DB_File was a method exported by MLDBM rather than a different module. I found and installed that, but I'm still getting this error "Argument "2.121_08" isn't numeric in subroutine entry at C:/Perl/site/lib/MLDBM/Serializer/Data/Dumper.pm line 5." Any idea what that's about?
        It might be time for you to show some code -- in particular, what you have on the same line with  use MLDBM and what the  tie statement looks like, along with anything else relevant to the latter.

        Now that you have DB_File installed, you could also test what happens when you open/tie your 5-yr-old data file as a plain-vanilla DB_File hash, just to make sure it's still readable, and to get a look at what the keys and values are.

        UPDATE: In case it helps, here's a quick/easy way to dump out the contents of a DB_File hash:

        use strict; use DB_File; my $Usage = "Usage: $0 db_file_name\n"; die $Usage unless ( @ARGV == 1 and -f $ARGV[0] ); my %file_hash; tie ( %file_hash, 'DB_File', $ARGV[0] ) or die "DB_File: $ARGV[0]: $!"; while ( my ( $key, $val ) = each %file_hash ) { print "key: $key\n$val\n;\n"; } untie %file_hash;
        Redirect STDOUT to some other file. It will have records delimited by "\n;\n", and each record will have at least two lines of data, the first line being the hash key (preceded by "key: ") and the second line (plus any additional lines preceding "\n;\n") being the value for that key.

        (another update: this assumes that your key strings do not contain line-breaks while you values might; in any case, you could also transliterate things to suit your taste -- e.g.  s/(\p{IsCntrl})/sprintf("0x{%02x}",ord($1))/ge; or something like that.)

        OK I tried to just read it with DB_File as you suggested, and it worked.

        The code:

        use strict; use MLDBM qw(DB_File); my $db = 'data_db'; my %records; my $dbh = tie %records, 'MLDBM', $db or die $!; my $junk = 1;
        Something else interesting: If I set a breakpoint on the last line and run it straight to there, I get the error about Dumper.pm. If I step through the tie statement with the debugger, I don't get the error. WTF? In that case the debugger lists type = exception for both $dbh and %records.

        Just an update on this: The Dumper.pm error was a warning not an error. I thought it was an error because the debugger (Komodo) couldn't see the tied hash. Just for yuks I tried to print out the keys of the hash, and it worked.

        So the bottom line is that once I installed DB_File it was working, but for some reason the debugger couldn't (and still can't) look at the tied hash.