PDA

View Full Version : dbm generation error


cooldaddy
11-20-2005, 10:59 AM
Hello, I'm using this line:

tie(%map, 'SDBM_File', '_voters', O_RDWR|O_CREAT, 0666) or die "Couldn't tie SDBM file 'filename': $!; aborting";

in my script to generate a dbm database... it used to work a few weeks ago. But now im getting this cgi error:


Couldn't tie SDBM file 'filename': No such file or directory; aborting at /home/users/web/b2495/hy.openbooks/cgi-bin/vote.pl line 30.

So it seems it cannot create the dbm file... how come ? is there anything wrong with my line ?


Ps. I can post more of my scripting if you guys want too

FishMonger
11-20-2005, 05:25 PM
Are you running the script in a cgi environment? If so, does the web server account have write access to the directory?

cooldaddy
11-20-2005, 05:49 PM
Yes, its running in cgi environment.. (ive got hypermart as host), and the webserver account has write access to the directory.

cooldaddy
11-20-2005, 06:25 PM
Oke, maybe you guys see the bug in this piece of my script.. (it's not my whole coding..but it's the part where the bug resides...


#!/usr/local/bin/perl
use CGI;
use Fcntl qw(:flock);
use SDBM_File;
use CGI;
use headups;
use MIME::Lite;
use lib "/home/users/web/b2495/hy.mysite/";
require Valid;
my $q = new CGI;
print $q->header, $q->start_html;
&butt;
@ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'});


if ($ARGV[1] eq ""){print qq{An error occured, please try again later.};exit;}
$user=uc($q->param('username'));

my $result = (Email::Valid->address($user) ? 'yes' : 'no');
($result eq "yes") ? print "" : &Error;

### it goes wrong at the following line

tie(%map, 'SDBM_File', '_voters', O_RDWR|O_CREAT, 0666) or die "Couldn't tie SDBM file 'filename': $!; aborting";

####

$error = 1 if $map{$user};

if ($error<1){
$string = join("\t",$user);
$map{$user} = $string;
print "Case1";
}else{
print "Case2";exit;
}

untie %map;

FishMonger
11-20-2005, 07:04 PM
I don't see anything wrong with the tie statement. Try using either the relative or absolute path to the file. You can also use touch to create an empty file then execute the script. If that works, then there’s something going on with the write permission.

cooldaddy
11-21-2005, 09:30 AM
Ok, it's solved.. this :

use Fcntl qw(:flock);

caused the problem, I changed it to

use Fcntl;

and now it works fine. What does qw(:flock); actually do ?
In one other script I want to open several plain text files and a dbm file, are the plain text files flocked correctly if I use:
use Fcntl;
instead of
use Fcntl qw(:flock); ?

FishMonger
11-21-2005, 04:26 PM
qw(:flock)Imports the symbolic names of the types of locks which allows you to use their names instead of their numbers.
'flock' => [qw(LOCK_SH LOCK_EX LOCK_NB LOCK_UN)]

It's more common to use qw(:DEFAULT). I'd need to double check the rules and methods for importing the modules name space, but it may be that when you used qw(:flock) it only imported that portion of the names and not the O_RDWR|O_CREAT. However, if that's the case, I would have expected a different error message.

cooldaddy
11-21-2005, 06:49 PM
So if I use:
use Fcntl;

and flock the plain text files with the flocknumbers I'll be allright ?

Thanks so far...you helped me a lot..

FishMonger
11-21-2005, 07:28 PM
If you use
use Fcntl;

You won't be able to use the symbolic names, instead you'll need to use their numbers; 1, 2, 4, or 8

I keep forgetting which number means what, which is why I use the symbolic names.

If you want the option to use all of the methods, import flock and default.

use Fcntl qw(:DEFAULT :flock);

You'll find the other names available to import from here.
http://search.cpan.org/src/NWCLARK/perl-5.8.7/ext/Fcntl/Fcntl.pm

cooldaddy
11-21-2005, 08:01 PM
Fishmonger...thank you very much for helping me out with this.. !!