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

Hi monks, Please enlighten me on the following code:
#!/usr/local/bin/perl use strict; use warnings; use DB_File; my (%h, $k, $v); my $file = "/tmp/data_db"; # This is the problem tie %h, "DB_File", "$file", O_RDWR|O_CREAT, 0777, $DB_HASH or die "Cannot open file $file $!\n"; $h{"apple"} = "red"; $h{"orange"} = "orange"; $h{"banana"} = "yellow"; $h{"tomato"} = "red"; # code to print keys and values of hash - no problem here
What puzzled me is the line my $file = "/tmp/data_db";There's no directory 'tmp' in the server and I've no idea where the database file 'data_db' is called. When I changed the directory 'tmp' to, say, 'data', the script died. Am I missing something? What's so special about 'tmp'? Why does the script work only with 'tmp' as the directory?

Replies are listed 'Best First'.
Re: DB_File - help
by PodMaster (Abbot) on Nov 24, 2002 at 15:01 UTC
    It's a permissions issue.
    Try the following
    my $dir = "/whatever"; my $file = $dir."/file"; die "cannot write to $dir : $!" unless -W $dir;
    I suggest you pick something in the form of /home/username/...

    update: There ain't nothing special about /tmp as far as perl/DB_File is concerned. /tmp must exist, otherwise the program would have died.


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      Thanks, PodMaster! I got it to work :) I was changing the permission via WS_FTP (the GUI FTP program) and for some reasons, that didn't work. After I read your advice, I got into the server using MS-DOS FTP and typed the command to chmod the directory to 777. That worked! Been stucked for hours until you came to my rescue :)