
rork
User
Jul 2, 2006, 7:52 AM
Post #2 of 5
(1053 views)
|
|
Re: [graemep] Lookup and re-direct
[In reply to]
|
Can't Post
|
|
#!/usr/bin/perl use CGI qw(:standard); # use CGI::Carp qw(fatalsToBrowser) use strict; use warnings; my $q = new CGI; my $from_url = $q->param('url'); my $to_url my $dbase = "dbase.txt"; open(FILE, "<", $dbase) or die "Can't open $dbase: $!"; while(<FILE>) { chomp; my ($url1, $url2) = split(/\t/, $_); if ($url1 eq $from_url) { $to_url = $url2; last; } } close(FILE); if ($to_url) { print $q->redirect($to_url); } else { print $q->header; print "Couldn't find $from_url"; } Name your text input 'url' You might have to modify the delimiter in the split function (currently tab), the filename of your database and the shebang line. To retrieve better error messages in CGI uncomment use CGI::Carp The code is untested but should give you an idea. -- Don't reinvent the wheel, use it, abuse it or hack it.
|