Skip to content

Instantly share code, notes, and snippets.

@terryjbates
Created September 27, 2012 02:58
Show Gist options
  • Save terryjbates/3791909 to your computer and use it in GitHub Desktop.
Save terryjbates/3791909 to your computer and use it in GitHub Desktop.
Perl program to generate a .dbm file given a .txt file to be used by RewriteMap directive. Faster!
#!/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 (<TXT>) {
next if (/^\s*#/ or /^\s*$/);
$DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/);
}
untie %DB;
close(TXT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment