DB_File tie error

J

Janna

Hello all,

I've convinced myself that the error message I'm getting from my Perl
script is sufficiently bizarre to ask for help here, but as always, it
may be that I'm making a stupid mistake as I'm fairly new to Perl.

I have a program that contains several blocks of code that are either
executed or not, depending on options specified in the command line or
through interaction with the user. Each of my 4 blocks involves
accessing a DBM file. I'll call the blocks LIT, CON, EXP, and ASSOC.
The order in which I just listed the blocks is the order in which they
appear in the program.

My problem is with the EXP block. At the beginning of the block is the
following code:

my $dbloc = "/data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db";
my %exphash;
my $expdb = tie %exphash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or die
"Cannot open this file $dbloc: $!\n";

Here's where it gets interesting. If the user specifies options such
that the EXP block is run by itself, or in any combination with the CON
and ASSOC blocks, everything's fine. If, however, the LIT block
executes, I get an error message that *starts with* "Cannot open this
file /data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db:" If the
program is running interactively, there's no further information. If
it's running with options specified at the command line, following the
colon in the original error message is "No such file or directory".

Here is some of the original code, for the first three blocks:

LIT block
unless ($litweight == 0 and $onehitlitweight == 0) {
#Open the BTREE with the publicationsmy $dbloc =
'/data3/mcleod.3/aldi/janna/candid/BUILD2/humanpubs.db';
$DB_BTREE->{'flags'} = R_DUP;
my %pubhash;
my $pubdb = tie %pubhash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or die "Cannot open $dbloc: $!\n";

#Open the BTREE with totalpubs
my $totalloc = '/data3/mcleod.3/aldi/janna/candid/BUILD2/totalpubs.db';
$DB_BTREE->{'flags'} = R_DUP;
my %totalpubhash;
my $totalpubdb = tie %totalpubhash, "DB_File", $totalloc,
O_RDWR|O_CREAT, 0640, $DB_BTREE or die "Cannot open $totalloc: $!\n";

undef $pubdb;
untie %pubhash;
undef $totalpubdb;
untie %totalpubhash;
}

CON block
unless ($conweight == 0) {
#Load BTREE of Homologene data.
my $dbloc = '/data3/mcleod.3/aldi/janna/candid/BUILD2/humanhomol.db';
my %homolhash;
my $homoldb = tie %homolhash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or die "Cannot open $dbloc: $!\n";
undef $homoldb;
untie %homolhash;
}

EXP block
unless ($expweight == 0) {
my %tissuehash;
foreach (my $count=0; $count<@exptissues; $count++) {
$tissuehash{$exptissues[$count]} = 1;}
# Load exphash
my $dbloc = "/data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db";
my %exphash;
my $expdb = tie %exphash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or die "Cannot open this file $dbloc: $!\n";

undef $expdb;
untie %exphash;
}


There's more code I can include if needed, and I've chopped out the
guts of each block where the operations with the hashes are performed.


That said...any insight?
 
J

J. Gleixner

Janna said:
Here is some of the original code, for the first three blocks:

LIT block
unless ($litweight == 0 and $onehitlitweight == 0) {
#Open the BTREE with the publicationsmy $dbloc =
'/data3/mcleod.3/aldi/janna/candid/BUILD2/humanpubs.db';

That's exactly how your code appears??.. mmm.. that whole line is
commented out, so dbloc isn't defined.

Let perl help you.

use strict;
use warnings;
 
J

Janna

I'm sorry - when I pasted the code into my original message, everything
was pasted as one line, and I apparently missed a line break when I
re-entered them. It really appears in the code as:

#Open the BTREE with the publications
my $dbloc = '/data3/mcleod.3/aldi/janna/candid/BUILD2/humanpubs.db';
$DB_BTREE->{'flags'} = R_DUP;
my %pubhash;
my $pubdb = tie %pubhash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or die "Cannot open $dbloc: $!\n";

Also, I have "use strict; use warnings;" at the beginning of my script,
and also in the blocks, just in case. If perl wants to help me, I
suppose it's going to have to talk a little louder.
 
X

xhoster

Janna said:
Here's where it gets interesting. If the user specifies options such
that the EXP block is run by itself, or in any combination with the CON
and ASSOC blocks, everything's fine. If, however, the LIT block
executes, I get an error message that *starts with* "Cannot open this
file /data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db:" If the
program is running interactively, there's no further information. If
it's running with options specified at the command line, following the
colon in the original error message is "No such file or directory". ....



EXP block
unless ($expweight == 0) {
my %tissuehash;
foreach (my $count=0; $count<@exptissues; $count++) {
$tissuehash{$exptissues[$count]} = 1;}
# Load exphash
my $dbloc = "/data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db";
my %exphash;
my $expdb = tie %exphash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or die "Cannot open this file $dbloc: $!\n";

Add some additional diagnostic things here.

my $expdb = tie %exphash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or do {
warn "-e ", -e $dbloc, " -f ", -f $dbloc;
warn "@{[stat $dbloc]}";
die "Cannot open this file $dbloc: $!\n";
};


undef $expdb;
untie %exphash;
}

There's more code I can include if needed, and I've chopped out the
guts of each block where the operations with the hashes are performed.

Have you run the program with those guts chopped out to see if the error
reproduces that way?

Xho
 
J

Janna

I copied my program to another file and drastically edited it to about
75 lines (from over 1000) that duplicate the problem. I also added
Xho's suggested warnings. Here's the complete code now (sorry for the
length):

#!/usr/bin/perl

use strict;
use warnings;
use Fcntl;
use DB_File;

my $expweight = 0; # Will hold the user's expression weight
my $litweight=1; # Will hold the user's literature (>1 hit)
weight
my $conweight=0; # Will hold the user's conservation weight#

LIT BLOCK
unless ($litweight == 0) {
use strict;
use warnings;

#Open the BTREE with the publications
my $dbloc = '/data3/mcleod.3/aldi/janna/candid/BUILD2/humanpubs.db';
$DB_BTREE->{'flags'} = R_DUP;
my %pubhash;
my $pubdb = tie %pubhash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or die "Cannot open $dbloc: $!\n";

#Open the BTREE with totalpubs
my $totalloc = '/data3/mcleod.3/aldi/janna/candid/BUILD2/totalpubs.db';
$DB_BTREE->{'flags'} = R_DUP;
my %totalpubhash;
my $totalpubdb = tie %totalpubhash, "DB_File", $totalloc,
O_RDWR|O_CREAT, 0640, $DB_BTREE or die "Cannot open $totalloc: $!\n";

undef $pubdb;
untie %pubhash;
undef $totalpubdb;
untie %totalpubhash;
}

# CON BLOCK
unless ($conweight == 0) {

#Load BTREE of Homologene data.
my $dbloc = '/data3/mcleod.3/aldi/janna/candid/BUILD2/humanhomol.db';
my %homolhash;
my $homoldb = tie %homolhash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or die "Cannot open $dbloc: $!\n";

undef $homoldb;
untie %homolhash;
}

# EXP BLOCK
unless ($expweight == 0) {

# Load exphash
use strict;
use warnings;
my $dbloc = "/data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db";
my %exphash;
my $expdb = tie %exphash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or do {
warn "-e ", -e $dbloc, " -f ", -f $dbloc;
warn "@{[stat $dbloc]}";
die "Cannot open this file $dbloc: $!\n";
};

undef $expdb;
untie %exphash;
} #unless

exit;


As I said before, it requires $expweight AND $litweight to be nonzero
in order to reproduce the error. If $expweight is nonzero and
$litweight and $conweight are both 0, the error does not occur.
Likewise, if $litweight and $conweight are nonzero, but $expweight is
0, the error does not occur.

When I run the program as above ($expweight and $litweight = 1), this
is what I get as the output:
-e 1 -f 1 at ./gutless.pl line 704.
2067 7372805 33188 1 1067 1067 0 87662592 1168557177 1168538256
1168538256 4096 171392 at ./gutless.pl line 705.
Cannot open this file
/data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db: No such file or
directory

I have no idea what the 'warn "@{[stat $dbloc]}";' line Xho suggested
does, so if the answer is obvious from that output, I apologize for my
lack of Perl skills.

Thanks,

Janna

Janna said:
Here's where it gets interesting. If the user specifies options such
that the EXP block is run by itself, or in any combination with the CON
and ASSOC blocks, everything's fine. If, however, the LIT block
executes, I get an error message that *starts with* "Cannot open this
file /data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db:" If the
program is running interactively, there's no further information. If
it's running with options specified at the command line, following the
colon in the original error message is "No such file or directory". ...



EXP block
unless ($expweight == 0) {
my %tissuehash;
foreach (my $count=0; $count<@exptissues; $count++) {
$tissuehash{$exptissues[$count]} = 1;}
# Load exphash
my $dbloc = "/data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db";
my %exphash;
my $expdb = tie %exphash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or die "Cannot open this file $dbloc: $!\n";

Add some additional diagnostic things here.

my $expdb = tie %exphash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or do {
warn "-e ", -e $dbloc, " -f ", -f $dbloc;
warn "@{[stat $dbloc]}";
die "Cannot open this file $dbloc: $!\n";
};


undef $expdb;
untie %exphash;
}

There's more code I can include if needed, and I've chopped out the
guts of each block where the operations with the hashes are performed.

Have you run the program with those guts chopped out to see if the error
reproduces that way?

Xho
 
J

J. Gleixner

Janna wrote:
[...]
As I said before, it requires $expweight AND $litweight to be nonzero
in order to reproduce the error. If $expweight is nonzero and
$litweight and $conweight are both 0, the error does not occur.
Likewise, if $litweight and $conweight are nonzero, but $expweight is
0, the error does not occur.

It's occurring on the humanexp.db file, so you can narrow it down to:

use Fcntl;
use DB_File;
use strict;
use warnings;

$DB_BTREE->{'flags'} = R_DUP;
my $dbloc = '/data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db';
my %exphash;
my $expdb = tie %exphash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or do {
warn "-e ", -e $dbloc, " -f ", -f $dbloc;
warn "@{[stat $dbloc]}";
die "Cannot open this file $dbloc: $!\n";
};

Does that fail too?
When I run the program as above ($expweight and $litweight = 1), this
is what I get as the output:
-e 1 -f 1 at ./gutless.pl line 704.
2067 7372805 33188 1 1067 1067 0 87662592 1168557177 1168538256
1168538256 4096 171392 at ./gutless.pl line 705.
Cannot open this file
/data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db: No such file or
directory

I have no idea what the 'warn "@{[stat $dbloc]}";' line Xho suggested
does, so if the answer is obvious from that output, I apologize for my
lack of Perl skills.

perldoc -f stat

Is that file a DBM file?

Run the following, from your command line, and show us the output:

file /data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db
file /data3/mcleod.3/aldi/janna/candid/BUILD2/totalpubs.db

Also, for fun,

ls -l /data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db
ls -l /data3/mcleod.3/aldi/janna/candid/BUILD2/totalpubs.db
ls -l /data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp*

If that file is a text file, or a non-DBM file, you should
get a different error, but the output from ls and file
might help diagnose the issue.

It might be an issue with how it was created, maybe a
different DBM version, different OS, etc. Maybe it wasn't
created with R_DUP? I don't know, just throwing out
possible problems.
 
P

Paul Marquess

Janna said:
I copied my program to another file and drastically edited it to about
75 lines (from over 1000) that duplicate the problem. I also added
Xho's suggested warnings. Here's the complete code now (sorry for the
length):

#!/usr/bin/perl

use strict;
use warnings;
use Fcntl;
use DB_File;

my $expweight = 0; # Will hold the user's expression weight
my $litweight=1; # Will hold the user's literature (>1 hit)
weight
my $conweight=0; # Will hold the user's conservation weight#

LIT BLOCK
unless ($litweight == 0) {
use strict;
use warnings;

#Open the BTREE with the publications
my $dbloc = '/data3/mcleod.3/aldi/janna/candid/BUILD2/humanpubs.db';
$DB_BTREE->{'flags'} = R_DUP;
my %pubhash;$DB_BTREE->{'flags'} = R_DUP;
my $pubdb = tie %pubhash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or die "Cannot open $dbloc: $!\n";

#Open the BTREE with totalpubs
my $totalloc = '/data3/mcleod.3/aldi/janna/candid/BUILD2/totalpubs.db';
$DB_BTREE->{'flags'} = R_DUP;
my %totalpubhash;
my $totalpubdb = tie %totalpubhash, "DB_File", $totalloc,
O_RDWR|O_CREAT, 0640, $DB_BTREE or die "Cannot open $totalloc: $!\n";

undef $pubdb;
untie %pubhash;
undef $totalpubdb;
untie %totalpubhash;
}

# CON BLOCK
unless ($conweight == 0) {

#Load BTREE of Homologene data.
my $dbloc = '/data3/mcleod.3/aldi/janna/candid/BUILD2/humanhomol.db';
my %homolhash;
my $homoldb = tie %homolhash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or die "Cannot open $dbloc: $!\n";

undef $homoldb;
untie %homolhash;
}

# EXP BLOCK
unless ($expweight == 0) {

# Load exphash
use strict;
use warnings;
my $dbloc = "/data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db";
my %exphash;
my $expdb = tie %exphash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
$DB_BTREE or do {
warn "-e ", -e $dbloc, " -f ", -f $dbloc;
warn "@{[stat $dbloc]}";
die "Cannot open this file $dbloc: $!\n";
};

undef $expdb;
untie %exphash;
} #unless

exit;


As I said before, it requires $expweight AND $litweight to be nonzero
in order to reproduce the error. If $expweight is nonzero and
$litweight and $conweight are both 0, the error does not occur.
Likewise, if $litweight and $conweight are nonzero, but $expweight is
0, the error does not occur.

When I run the program as above ($expweight and $litweight = 1), this
is what I get as the output:
-e 1 -f 1 at ./gutless.pl line 704.
2067 7372805 33188 1 1067 1067 0 87662592 1168557177 1168538256
1168538256 4096 171392 at ./gutless.pl line 705.
Cannot open this file
/data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db: No such file or
directory

You sometimes set this before opening a database

$DB_BTREE->{'flags'} = R_DUP;

The problem with that is $DB_BTREE is a global data structure, so once set
it will remain set till the program terminates or something else changes
it. You don't change it.

So if your LIT block sets it, it will still remain set when the CON block is
executed. But if the LIT block isn't executed, the CON block will be
executed without R_DUP. This is a bad idea. You should reset
$DB_BTREE->{'flags'} after each tie.

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top