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

I'm running a site that is going to need a way to keep track of updates. It's currently using no database for updaptes. They're simply kept in files in one directory. Symlinks are made from a category directory (such as "General.cat") to the actual file. Then I also have a directory for staff, which contains one directory per user (so /updates/staff/jquser/ would contain symlinks for jquser that point to the actual files in /updates/).

I recently started using dbm for some other work I was doing: storing staff passwords, email addresses, and other configuration. It's now easier to just open the dbm database and have all the values there to access. However, I wonder how I might apply this to my problem.

While I don't have many updates now (<30), I intend for there to be a good deal of them. Some not too large - a paragraph or so - others full editorial-sized posts. I know DBM has a limit to the number of bytes (1000, IIRC) it can hold, so storing an entire post would not be effecient. Also, I want to have as much static content as possible: serve just the HTML files for the posts and not make a Perl script read the post and print it every time someone views it.

So here's my dilemma: do I use DBM, first of all, or is there a better Perl-based DB to use? I don't have MySQL or any other DB program installed on my server, and even so, I've never used any other DB than dbm. I don't have the knowhow to interface with any other DB (at least yet), so hopefully it can be some fairly simple solution. If I use DBM, I have one of two options: have one fairly large DB file to hold all relevant information about the updates: who posted it, the subject, and the day/time posted (for archival purposes, it would be accessed fairly often to print out a list of recent updates by some user, in some category, or just most recent posts). The other option would be to have a few databases: one for "all updates," one per category, and one per staff member. When viewing the archives for posts by jquser, it would only need to open jquser's DB, and thus wouldn't have to sift through anyone else's posts.

I'm kind of leaning towards the second option because it would result in quicker access time for any given archive section. No need to sift through 150 posts to see the most recent 25 posts by jquser. However, in this case, there would be at least three times the disk space used; for each update, the info gets posted into the "all updates" db, the db for the specific category, and the db for jquser. Though there shouldn't be all that much in each DB - URL of the file (only one file, no symlinks in this case), day/time posted, posted by whom, their email address, subject, etc.

Pretty long-winded, but I hope someone out there has more experience with this kind of thing and can help me out.

Thanks!

Replies are listed 'Best First'.
Re: DBM (or something better?) question
by perrin (Chancellor) on Oct 03, 2002 at 16:42 UTC
    Your multi-dbm file approach sounds solid and will be very fast. Use DB_File or GDBM and you won't have to worry about any size limits.
Re: DBM (or something better?) question
by Anonymous Monk on Oct 03, 2002 at 03:12 UTC
    Which DBM are you using? SDBM?

    If so then install DB_File and get rid of the size limit. The interface is the same as the one you are using. Note: The tie interface is better than the built-in dbmopen hack. Installing a new type of dbm won't break working programs with tie. It will with dbmopen.

      This is twice in one day that I've run-across the mention of dbmopen.

      Why hasn't dbmopen been completely deprecated in favor of tie?

Re: DBM (or something better?) question
by BUU (Prior) on Oct 03, 2002 at 00:14 UTC
    To take somewhat of a tangent approach, what you're describing sounds a lot like something along the lines of slashcode, or possibly everything engine. Could you just bastardize one of these for your creation?
      The problem is, both of those use MySQL as their backend, if I'm correct. He says he can't use MySQL.

      So, to the original poster: You can't use DBM. You can't install an SQL database..

      AFAIK you're out of luck. There are many good database products out there, and if you can't use them, well... you can't use them.

      The only thing I could think of would be to use flat files or to write your own ISAM type database in perl. And I don't want to think about that.

      --
      perl: code of the samurai