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

I've been using some old perl scripts for years now that manipulate some databases. These perl scripts all open the database using the line:

dbmopen(%DATA, "filename", 0600) || die "Darn!";

On my Linux server, this line creates or opens a single "filename.db" file. Great. I don't really care what is going on under the covers at this point. I'm just happy that it works!

The problem occurred when I recently tried to port my old perl scripts over to Windows and ran into some trouble. (Surprise!) I got apache and perl running easily enough on Windows 2000, and my perl script even ran the first time I tried it in the Apache cgi-bin! But my script didn't find any records in the database. (I had already binary ftp'd the filename.db file from the Linux server to the appropriate place on the Windows machine.) But when I executed my perl script, it appeared to ignore the filename.db file and it created two files ... filename.dir and filename.pag

I'm pretty stupid about the different database formats, so could anyone tell me how to force my Windows Perl install to open and modify the filename.db file instead of these new dir/pag files.

Thanks for any newbie advise you can give,
Kurt (kleucht)

Replies are listed 'Best First'.
Re: newbie: DB versus DIR/PAG database files
by Cody Pendant (Prior) on Sep 23, 2003 at 02:05 UTC
    See the documentation on dbmopen() at http://www.perldoc.com/perl5.8.0/pod/func/dbmopen.html

    In particular the part which says

    You can control which DBM library you use by loading that library before you call dbmopen():
    use DB_File; dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db") or die "Can't open netscape history file: $!";

    Might help.



    ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print
      From original submitter:

      Yeah, I guess I need to install DB_File module and use it. Too bad I don't have administrative permissions on this machine. How can I get ahold of an unzipped version of the file "DB_File.pm"? I cannot install WinZip without Admin permissions.

      Kurt

        From original submitter

        Okay, I got DB_File installed using PPM. That worked great. Now without any file there, it creates the "filename.db" file and manipulates it fine. But when I copy my original "filename.db" file into it's place ... the one that was actually created on a Linux machine, it tells me it cannot open the file.

        I've FTP'd it using both BINARY and ASCII, and both give me the same error.

        I've messed with the file permissions and the file it is giving me an error on has the exact same permissions as the file it created successfully, so it cannot be a permission problem.

        Is there a potential disconnect with the Linux created file and the windows perl module? Can the Windows Perl module DB_File open a file that was created on a Linux machine?

        Thanks for any help you can give!
        Kurt (kleucht)

Re: newbie: DB versus DIR/PAG database files
by PodMaster (Abbot) on Sep 23, 2003 at 06:35 UTC
    Hi.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: newbie: DB versus DIR/PAG database files
by Roger (Parson) on Sep 23, 2003 at 02:14 UTC
    Try this -
    dbmopen(%DATA, "filename.db", 0600) || die "Darn!";
    The .dir and .pag is the ndbm database extension default on the Windows perl platform. Because when you try to open the file "filename" without the ".db" extension, the system will try to find matching "filename.dir" and "filename.pag" by default, when not found, the system will try to create one for you. Thus you need to be more specific and give "filename.db" instead.

    Another suggestion: use tie() instead of dbmopen, and also checkout the DB_File (for Berkley DB), DBI/DBD modules on CPAN, which are great for database manipulations.
      Tried this on my Win32 system (w/o DB_File installed) and it created "filename.db.pag" and "filename.db.dir".

      After installing module DB_File and adding "use DB_File;" before the dbmopen() AND using "filename.db" instead, a file was created with this name.   But I don't know if this is what the original poster needs - DB_File that is.   He needs to tell us more?

        He needs to tell us more?

        I don't think he does. He's moved his .db files to the new machine, but can't open them with dbmopen() because his version of dbmopen() finds that the .pag and .dir files don't exist and creates them. He needs to switch to DB_File to get the dbmopen() call to find and use the .db file.



        ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print