httpd-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrik Grip-Jansson <patr...@gnulix.org>
Subject Re: perl guru: mod_rewrite example
Date Sat, 02 Feb 2002 10:43:30 GMT
On Fri, 1 Feb 2002, Joshua Slive wrote:

> Does some kind perl guru out there want to look at 
> http://bugs.apache.org/index.cgi/full/9686
> see if this person makes sense and suggest an alternative.

He's right, and the proposed fix looks good. However, since we're redoing 
the script, we might as well fix some other stuff...

The following script adds some error checking and allows comments on the 
data rows (so that it works with the example "map.txt"). One could remove 
the parenthesis in the if:s, but I guess this isn't a round of golf :-) 
Anyhow, here is my proposal for a new txt2dbm:

#!/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 (<TXT>) {
  next if (/^\s*#/ or /^\s*$/);
  $DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/);
}

untie %DB;
close(TXT);

-- 
.---------------------.
| Patrik Grip-Jansson |
| Ringen 4B           |    .--------------------.
| 78444 Borlänge   .--'----' http://gnulix.com/ `---------.
| Sweden           |  All views and opinions are my own,  |
`------------------| PH:+46(0)24382823 PW:+46(0)707354360 |
                   `--------------------------------------'


---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org


Mime
View raw message