in reply to Re: Using Regexp Patterns as Variables
in thread Using Regexp Patterns as Variables
This code runs two sites, there is an admin function that allows site admins to create URL translators (old product links to new product links). Basically, they add patterns and those get stored in a database (it doesn't work yet though).
I don't want to hard code the patterns (as both sites are very different) and also there needs to be a way to add these rules as broken links are found.
Make sense? Code looks something like this:
my $req = $ENV{REQUEST_URI}; ## Get rules my $query = qq~ SELECT incoming, outgoing, id FROM url_translate ~; my $sth = $dbh->prepare($query); my $rv = $sth->execute; while (my $r = $sth->fetchrow_hashref) { my $in = $r->{incoming}; my $out = $r->{outgoing}; # if( s#$in#$out#i ) { if( $req =~ s#/Products/bt-(.*?).aspx#/s/Products/$1#i + ) { $ENV{REQUEST_URI} = $req; return; } } return;
|
|---|