More ModRewrite - Using a dbm file instead of a txt file

M

The most confusing thing is when you use the perl script on the official apache site here it's written for the NDBM format (which isn't available on my box).

Here's the perl script:

#!/path/to/bin/perl
##
##  txt2dbm -- convert txt map to dbm format
##

use NDBM_File;
use Fcntl;

($txtmap, $dbmmap) = @ARGV;

open(TXT, "<$txtmap") or die "Couldn't open $txtmap!n";
tie (%DB, 'NDBM_File', $dbmmap,O_RDWR|O_TRUNC|O_CREAT, 0644)
  or die "Couldn't create $dbmmap!n";

while () {
  next if (/^s*#/ or /^s*$/);
  $DB{$1} = $2 if (/^s*(S+)s+(S+)/);
}

untie %DB;
close(TXT); 

So after some trial and error, I found out that my version of apache works with SDBM, and it appears that if you just change NDBM to SDBM it works...

#!/usr/bin/perl -w
##
##  txt2dbm -- convert txt map to dbm format
##

use SDBM_File;
use Fcntl;

($txtmap, $dbmmap) = @ARGV;

open(TXT, "<$txtmap") or die "Couldn't open $txtmap!n";
tie (%DB, 'SDBM_File', $dbmmap,O_RDWR|O_TRUNC|O_CREAT, 0644)
  or die "Couldn't create $dbmmap!n";

while () {
  next if (/^s*#/ or /^s*$/);
  $DB{$1} = $2 if (/^s*(S+)s+(S+)/);
}

untie %DB;
close(TXT);

So problem 1 fixed. Then I find out the output of this thing is two files instead of one...wtf? The files are named: rewritemap.dbm.dir and rewritemap.dbm.pag

Here's the short answer: If you just ignore the additional extensions, it will work. Here's the httpd.conf line:

RewriteMap redirects dbm:/.../.../.../rewrite/rewritemap.dbm

Archived Comments


Great article! Thanks for clearing up this otherwise poorly-documented issue.

Posted by Nick on October 18th, 2007



Yes, thank you very much. I ran in to the exact same problem. From what I gather you can only use

use NDBM_File;

With Perl 5.10

And I couldn't upgrade my system to this version.

Many thanks!

Posted by Kevin Smith on July 31st, 2008



One small typo.

while ()

Should be:

while (<TXT>)

-Peter

Posted by Peter Burkholder on April 09th, 2009

About the author

Jeremy Tunnell
I study meditation and write some software.

Comments

Get in touch

You can reach Jeremy at [email protected]