EchoAngel has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I finally got the CGI::Explorer package to work. However, it is quite limited in my usage. So I have to include urls for every tree link. I am using GET method for processing the data. I have the absolute url and I want to add variables and values to it. What is the syntax for it? Is there a simple way? For example, say I have fruit = banana. I know I would do www.myscript.cgi?fruit=banana. But how would it work if my variables/values have any kind of characters (say %)?
  • Comment on Perl/Cgi : How to Create Url with variables and values (get method) from Scrach?

Replies are listed 'Best First'.
Re: Perl/Cgi : How to Create Url with variables and values (get method) from Scrach?
by Frantz (Monk) on Jan 27, 2005 at 22:56 UTC
    You must encode the values.

    See the source code of CGI::Util

    in escape function :

    $toencode =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg +;
      thanks! this helps!
Re: Perl/Cgi : How to Create Url with variables and values (get method) from Scrach?
by amw1 (Friar) on Jan 27, 2005 at 22:41 UTC
    You'll want to use something like URI::Escape on your keys and values. This will do things like turn the string

    Hi There into Hi%20There

    So you don't confuse the browser/script.

    I know that CGI.pm automatically deals with translating from URI encoded strings when you get them from the object, I haven't used CGI::Explorer so you may need to manually decode them as well.