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

Still not working: I donno what the problem is. but it still says cant open file. I guess it must be problem with the DB_FILE module. I installed it as per the readme.txt in the DB_FILE module. I read the documentation too. Do I need to set a link or path variables etc..Would perl automatically recognize the DB_FILE module, no matter where it is installed. Thanks for your update. I have aproblem with opening the history file. it prints out the comment in the die case "can't open history file" and says line 7. can anyone help me out with this please. thanks in advance
use DB_File; use CGI; use DirHandle; use FileHandle; dbmopen(%TEST, "/home/lab/history.db", 0666) or die "Can't open histor +y file: $!"; while (($key) = each %TEST){ print $TEST($key) } dbmclose(%TEST);

Replies are listed 'Best First'.
Re: newbie-probelm opening file
by Happy-the-monk (Canon) on Jun 03, 2004 at 21:46 UTC

    what does it say after "Can't open history file: " and before it says "line 7"? That's what should tell you - or us.

    Update:
    Yes, if the file exists and the permissions are as you said, that should work indeed.

    Update 2:
    perldoc -f dbmopen   suggests this code:

    while (($key,$val) = each %TEST) { print $key, ' = ', unpack('L',$val), "\n"; }

      it simply says "can't open history file: at test.pl line 7". no more error messages or anything. i'm a newbie, just trying to open and print the contents of the file. i set the file permission for the history.db as 0700. so accessing it shouldnt be a problem..right?? tia have one more doubt, if i wanna print the value along with key, can i use
      dbmopen(%TEST, "/home/lab/history.db", 0666) or die "Can't open histor +y file: $!"; while (($key,$value) = each %TEST){ print "$key.$value\n";
Re: newbie-probelm opening file
by Anonymous Monk on Jun 04, 2004 at 14:39 UTC
    Why not use IO::All ?

    use IO::All; print "$_\n" for keys %{ io('/home/lab/history.db') };