SPUG: Encoding CGI params

Martin, Asa asa.martin at attws.com
Mon Jun 17 18:59:21 CDT 2002


I have a simple CGI program that allows users to search a directory of text
files by regular expression. It is using a GET form so when the form is
submitted the regular expression gets encoded on the URL line with all the
necessary characters replaced with %stuff. I like using CGI.pm because then
I don't have to know how this is done. It just works, even with complicated
regular expressions.

On the search results page, each file that contained that regular expression
is presented as a link, and when they click the link, the file is displayed
in the browser. I'd like for the searched for string to be highlighted in
the window. This works by making the link to view the file something like
this:

/mysite/cgi-bin/script.cgi?action=view&filename=$filename&regex=$regex

Then in script.cgi, I replace everything that matches $regex in red font.
However this fails when the $regex contains strange characters or spaces.
How do I encode the regex and then use it in the link output? I looked
through the CGI.pm module for an encode routine, but it wasn't very clear.
It would be great if I could call a CGI routine directly to encode it.

Hope this makes sense. 

Thanks in advance.

Asa

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org




More information about the spug-list mailing list