in reply to using hash to lookup value
Rolling your own CGI parameter parsing is not recommended but nothing stops from you doing that. Well, if you insist....
But, if you don't mind to use a CPAN module (I do recommend it), you can use CGI.pm or CGI::Simple. I assumed that the topic is requested with topic parameter (such as http://www.example.com/cgi-bin/help.cgi?topic=user) and that each topic has a corresponding html file.my %params; # declare a hash to hold the params later if ($ENV{REQUEST_METHOD} eq 'GET' && $ENV{QUERY_STRING} ne '') { .... foreach .... { my($name, $value) = split .... # get the name and value ..... # cleaning name and value $params{$name} = $value; # hash assignment } }
#!/usr/bin/perl use strict; use warnings; use CGI::Simple; my $baseurl = 'http://www.example.com/helps'; my %available_topics = ( home => 'home.html', user => 'user.html', add => 'add.html', update => 'update.html', remove => 'remove.html', #... other help topics ); my $default_topic = 'home'; my $cgi = CGI::Simple->new; # let CGI::Simple does the parsing my $topic = $cgi->param('topic') || ''; # get the wanted topic # get corresponding html file my $help_file = $available_topcs{$topic} || $available_topics{$default +_topic}; # send redirection print $cgi->redirect("$baseurl/$help_file");
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: using hash to lookup value
by grashoper (Monk) on Oct 16, 2007 at 03:52 UTC | |
by Gangabass (Vicar) on Oct 16, 2007 at 04:07 UTC |
In Section
Seekers of Perl Wisdom