in reply to Re: Database problem
in thread Database problem

Thank you that took care of the invalid argument error. But now i have this error

Can't open /home/k0rn/data/dbapache : No such file or directory

Also get this error but have had this for awhile

Premature end of script headers: register.pl,

That problem is from header sub routine im asumeing. Witch is this

# Header subroutine

sub HEADER {
my($title) = @_;
print <<EOT;
<HTML>
<HEAD>
<TITLE>$title</TITLE>
</HEAD>
<body bgcolor="#263C6D" text="white" link="#ffffff"
vlink="#C0C0C0" alink="#C0C0C0">


EOT
}


When the file and directory is their. I don't get that. But thank you on your help. I noticed those modes in my Perl books and so fourth but didn't think it was nessicary. Apparently i was wrong heh.

Replies are listed 'Best First'.
Re^3: Database problem
by alexm (Chaplain) on Apr 20, 2008 at 14:59 UTC
    Can't open /home/k0rn/data/dbapache : No such file or directory
    This error message is clear enough. Does the file actually exist?
    Premature end of script headers: register.pl
    This usually means that the CGI died before completing its task, as in the case of the other message above. Please, note the tie ... or die ... construct will abort the execution of the CGI if anything goes wrong with the tie.
      I made a Perl script to create the databases. And now their isn't a cant find the file or directory error. But now theirs this error.

      AnyDBM_File doesn't define an EXISTS method at /home/k0rn/public_html/register.pl line 75

      this is line 74

      tie(%DBAPACHE, "AnyDBM_File", $dbapache, 0644, O_RDWR|O_CREAT) or die "Can't open $dbapache : $!\n";

      And this is line 75 were the error is from.

      unless(exists($DBAPACHE{$name})) { # Check if exists in database

      Im pretty new to Perl but i don't think that is incorrect.

        No it's not your fault.

        AnyDBM_File is a thin wrapper over any of NDBM_File, DB_File, GDBM_File, SDBM_File and ODBM_File which are a series of different flavours. What AnyDBM_File does is try to load each one (in the order stated) and uses the first working version. My Perl (5.8.8 on Win 32) uses SDBM_File which does define an EXISTS method so does not choke. It looks like dbmmanage insists on SDBM_File (at least on the Apache 2 Win32 port).

        Tied hashes require that a number of methods get defined. If they are not things default back to the code in Tie::Hash which in the case of exists is to choke with the error you note. The only way to fix this properly is to patch the source of whatever *DB_File your system is using and add the missing method. As noted it works fine for me so it has quite probably already been fixed and you just have an old version of *DB_File.

        Anyway the quick fix answer is don't use exists. Use defined instead.

        unless(defined $DBAPACHE{$name}) {
        Presumably the DB_File version you are using does not autovivify (create the hash entry) so it will work fine. If not I'm sure someone will patch it by adding the missing EXISTS tie method to the XS.

        To find out which version of *DB_File you are actually using try this simple test code (adjust the file path as required and the test username):

        use strict; use Fcntl; use AnyDBM_File (); my $file = "C:/dbase"; # no file extension as dbmmanage chops this of +f our @ISA; my %DB; tie (%DB, "AnyDBM_File", $file, 0666, O_RDWR|O_CREAT ) or die "Can't tie $file: $!"; print "ISA @AnyDBM_File::ISA\n"; #my $user = 'test'; #if (exists $DB{$user}) { # print "$user:$DB{$user} found!\n"; #} untie %DB; __DATA__ SDBM_File test:password found!