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

Hi,
I installed a number of scripts that work quite well on my server but I do get an error message "Sorry, can't open database file." The directoery database as well as the file database.txt have 644 permissions. Here is part of the script:

sub search_files { if ($USE_DBM) { while (($file, $file_path) = each(%f_file_db)) { search_contents($file, $file_path); } } else { my $file_count = 0; open (FILEDB, $DATABASEFILE) || die "Sorry, can't open databas +e file.\n"; foreach (<FILEDB>) { $file_count++; ($f_file_db{$file_count}, $filenames_db{$file_count}, $f_d +ate_db{$file_count},$f_size_db{$file_count},$f_termcount_db{$file_cou +nt},$descriptions_db{$file_count},$titles_db{$file_count},$contents_d +b{$file_count},$alt_text_db{$file_count},$meta_description_db{$file_c +ount},$meta_keywords_db{$file_count},$meta_author_db{$file_count},$li +nks_db{$file_count}) = split /\t/, $_; my $filepath = $f_file_db{$file_count}; search_contents($file_count, $filepath); } close(FILEDB); } }

I appreciate any and all suggestions of a possible solution. Thanks,
Karl

Replies are listed 'Best First'.
Re: help, please!
by toolic (Bishop) on Mar 14, 2010 at 02:40 UTC
    Get more specific error details by printing the value of $!:
    open (FILEDB, $DATABASEFILE) || die "<b>Sorry, can't open database fil +e. $?</b>\n";

    On a side note, please change the title of your post: How do I compose an effective node title?.

    Update: I incorrectly mentioned $?, but I meant to say $!. Thanks, NetWallah.

      Suerly, you mean "$!" , not "$?".

      To be canonical, the open should be:

      open (FILEDB, "<", $DATABASEFILE) or die "<b>Sorry, can't open data +base file $DATABASEFILE:<br/>$!</b>";
      $? deals with errors from child processes.
      $! deals with OS errors, including file open errors.

           Theory is when you know something, but it doesn't work.
          Practice is when something works, but you don't know why it works.
          Programmers combine Theory and Practice: Nothing works and they don't know why.         -Anonymous

        Thank you very much, Net. The script cannot find the text file and I have now something to work with. Your help is much appreciated.
        Karl I forgot a closing forward slash on the path to the directory with the result that it was looking for the directorytextfile.txt as the file name. Adding this $! is a great idea. Thanks again!
      Thanks for the help and also for the title criticism. It's appreciated. I did as suggested but still get the same error without any more specifics.
        Correction. I get the following error message:
        Sorry, can't open database file. 0
        My next question: What does this zero mean? Thanks,
        Karl