Created
September 27, 2012 02:58
-
-
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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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