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

This is the first experience I have with using a database in a different folder than the script that's calling it.

The code below produces "Cannot open file 'db': Bad file descriptor". Can anyone tell me why and what this error really means?

My first thought was it couldn't find the file so I intentionally changed the file path to something I knew didn't exist and the error was different (file not found error). So it's actually finding the file but it's erroring out anyway.

The folder the DB is in is 755 and the database is 644. The CGI script is in cgi-bin/stats/ and the database is in cgi-bin/track/link.db .

Any help would be very much appreciated!

#!/usr/bin/perl use warnings; use strict; use CGI::Carp qw(fatalsToBrowser); use CGI qw/:standard/; use POSIX; use DB_File; my $db = "/home/spyders/public_html/cgi-bin/track/link.db"; my %db; tie %db, "DB_File", "$db", O_CREAT | O_RDWR, 0644, or die "Cannot open file 'db': $!\n"; foreach (%db) { print "$_ => $db{$_}<br>"; }


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re: Cannot open file 'db': Bad file descriptor
by PodMaster (Abbot) on Jan 23, 2005 at 11:36 UTC
    Ask yourself, who is really responsible for the error message? It looks like its some function called from DB_File.xs (actually db_open). So to figure out what the error means you need to learn as much as you can about BerkeleyDB's db_open.

    A quick google for BerkeleyDB "Bad File Descriptor" yields an entry in http://www.sleepycat.com/xmldocs/ref/java/faq.html, which talks about it being an issue with large files, and that the solution is to upgrade (yes I know it talks about JNI, but you should try it anyway, as well as the --disable-largefile option).

    What you should do is use db_verify and db_stat to learn as much as you can about your file, and then try upgrading/re-compiling your BerkeleyDB (and subsequently your DB_File) to see if that does anything.

    My guess is that you'll probably have to contact the BerkeleyDB developers for help.

    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: Cannot open file 'db': Bad file descriptor
by aquarium (Curate) on Jan 23, 2005 at 12:50 UTC
    with DBM there's no notion of a database entity separate from a file representing some sub-entity -- as a single file (when you tie it) is a simple hash table. So it looks to me like you're confusing yourself, you sayd "DB" is something and "DATABASE" is something else. Guess what, DB stands for Database. Try using the path of the actual "DB" file you mentioned. Obviously link.db is not a dbm database/file/hash/table.
    the hardest line to type correctly is: stty erase ^H