SPUG: Encoding CGI params

O'neil, Jerome joneil at cobaltgroup.com
Mon Jun 17 19:12:58 CDT 2002


Don't use CGI to encode.  Use URI::Escape, or the query_form method off of
the URI class.

See the perldoc for the appropriate documentation.

-Jerome



-----Original Message-----
From: Martin, Asa [mailto:asa.martin at attws.com]
Sent: Monday, June 17, 2002 4:59 PM
To: spug-list at pm.org
Subject: SPUG: Encoding CGI params


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/archives/spug-list/attachments/20020617/ad38d27e/attachment.htm


More information about the spug-list mailing list