Rolling your own CGI parameter parsing is not recommended but nothing stops from you doing that. Well, if you insist....
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 } }
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.
#!/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!


In reply to Re: using hash to lookup value by naikonta
in thread using hash to lookup value by grashoper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.