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

I need to open a new db on the server using the dbmopen function.
$sonuc = dbmopen(param,$config_file,0666);
$config_file is defined, but this return null. I check with FTP and there is no file on server.

Please help me. It is urgent.

Sinan

Replies are listed 'Best First'.
Re: dbmopen does not work
by Fastolfe (Vicar) on Nov 19, 2000 at 22:43 UTC
    What is the bareword param there for? Shouldn't this be a hash?

    Are you checking for failure and printing an error message? That error message will probably help you a lot more than we can, given the information we have.

    dbmopen(%hash, $config_file, 0666) or die "Couldn't open DBM: $!";
    Note that dbmopen has been "largely superceded by tie":
    use NDBM_File; use Fcntl; tie(%hash, 'NDBM_File', $config_file, O_RDWR|O_CREAT, 0640) or die "Couldn't open NDBM: $!";
    If this is a CGI script you may need to examine the server error logs for the resulting error messages, or use something like CGI::Carp to send them to the browser:
    use CGI::Carp 'fatalsToBrowser';
      Thanks a lot for telling me about CGI::Carp. It really helped. But here is the error message:
      No such file or directory at /blah/blah/blah/cgi-bin/configure_counter +.pl line 54.
      I think that dbmopen is ougth to create the file... Is that wrong?
      param is a hash, but I think that you do not need to put the % at the beginning. Anyway, I tried it, still the same message.

      I need to finish this in a hurry, so I cannot user tie now, but next time I will.

      Thanks a lot for your help, Sinan
        Does your script have permissions to write to that directory? Most web configurations set themselves up so that they are restricted in what they can do/write. I believe dbmopen gives you a "No such file or directory" error instead of "Permission denied" if it simply cannot create the file due to a problem of this nature.

        Check your ownerships and permissions of the directory you're attempting to write to. You may have to create a new directory for CGI data files in such a way that the user the web server is running as can write to it.

        That, or use /tmp.

Re: dbmopen does not work
by arturo (Vicar) on Nov 19, 2000 at 22:48 UTC

    Well, for one, dbmopen doesn't return a handle, according to perlfunc:dbmopen. Second, as that document mentions, dbmopen is deprecated in favor of tie. But if you want to use dbmopen, to add stuff to the DBM file, you need to populate the variable you've called param.

    What's this do?

    my %param; dbmopen(%param, $config_file, 0666); # now populate the %param hash $param{key1} = "value1"; # or whatever makes sense dbmclose(%param);
    update And of course, as Fastolfe mentions, that first line should be dbmopen or die anyway. bad arturo!

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Re: dbmopen does not work
by a (Friar) on Nov 20, 2000 at 10:51 UTC
    You have lots of ground to cover before giving up on dbmopen. You might try putting in an 'or die "failed: $!"' and have dbmopen give you the reason it failed. But which database are you using, where is the db etc. Should 'param' be %param?

    try (sorry you'll have to link yourself):

    DBI 'home page': http://www.arcana.co.uk/technologia/perl/DBI
           
            Master archive site for Perl DB information:
                ftp://ftp.demon.co.uk/pub/perl/db/
            Mailing list archive:                /DBI/perldb-interest/
           
            Searchable index of the dbi-users mailing list:
            http://www.coe.missouri.edu/~faq/lists/dbiusers/
           
            mysql home page: http://www.tcx.se
    
    I didn't have much luck looking for dbmopen syntax on cpan, but everything there uses tie to tie a hash/array to a dbm file.

    But perldoc -f dbmopen says:

    among other things
        # print out history file offsets
        dbmopen(%HIST,'/usr/lib/news/history',0666);
        while (($key,$val) = each %HIST) {
            print $key, ' = ', unpack('L',$val), "\n";
        }
        dbmclose(%HIST);
    
    so param should at least be %param and it should be the hash you want connected/tied (perldoc also says dbmopen is outdated, use tie) to the dbm. I'm guessing you have a few other things not working too.

    HtH

    a

A reply falls below the community's threshold of quality. You may see it by logging in.