I just started to use DBM files in Perl. Unfortunately I have very bad manuals to teach the little things about it. My book consistently makes use of:
I've gathered that it is selecting a DBM package that is available on my computer. I got to thinking and said that if I use this method to create my DBM database files and then upload my .CGI script and DBM file to a server, the
Use AnyDBM_File line could possibly select a different DBM package. Therefore now I exclusively use: Use SDBM_FIle;
I hope this is correct.
Anyway, I created my DBM file with the following Perl script:
$value="$i"."c" x (29-length($i));
It creates a file with 5000 items in it each 29 bytes long. The DBM file seems to create 2 files on my computer: a .DIR file and a .PAG file. And for some reason the .DIR file is HUGE (1,048,576 bytes). I was only expecting the file size of 150,000 bytes or so. What happened?
Now from what I gather, DBM file are unique that they DON'T actually load the entire database file in. Using the hash array one can access items in it and do whatever. So the 1 megabyte size of the database is irrelevant since it is never loaded in. Is this all true?!
Now about File Locking (using FLOCK). I am testing all my web site CGI scripts on my Pentium Windows 95 computer. I use Perl 5 but it says that FLOCK isn't available on WIN95.
What I want to do is to be able to access the database file without having a million other users accessing it, altering it, and warping data I just read in and will soon write back out. Essentially I don't want to screw up the database if millions of users access it at once for reading/writing/updating. Alamo suggested FLOCK but I really couldn't find ANY information on it. Alamo, the only part I didn't get was the "recalling" of the script at the same time to test if FLOCK worked!? Maybe there's another method to locking files.