CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Search query values using cgi.pm

 



gNyan
Deleted

May 22, 2000, 8:13 AM

Post #1 of 2 (352 views)
Search query values using cgi.pm Can't Post

Hello

I made a simple search script, and to use multiple pages i need to pass the vars using cgi.pm
for example...
search.cgi?query=perl+guru&page=2

How do i get the script to transform the
'perl guru' that the user typed, into the 'perl+guru' ? And how to get it to interpret the 'perl+guru' as 'perl guru' when the user wants to view the next page?

Thanks to you all in advance


TheGame+
Deleted

May 21, 2000, 10:09 PM

Post #2 of 2 (353 views)
Re: Search query values using cgi.pm [In reply to] Can't Post

In fact, the browser translates what the user types into an URL-escaped string, and the CGI.pm module will translate it back to the original value.

This is usually the most handy, because you don't have to worry about how exactly these things are encoded.

So you'd simply get the original query by asking for it :
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

$query = param('query');
$page = param('page');</pre><HR></BLOCKQUOTE>

Unfortunately, the escape() and unescape() functions of CGI.pm are not directly available. So when you want to build your own links with the same query information, but with a different page number, it's probably easiest to change the page number like this :
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

for $nr (1 .. 10) {
param('page', $nr);
$myself = self_url();
print a({href=>$myself},$nr), " ";
}
</pre><HR></BLOCKQUOTE>

You can use similar code if you're using the object-oriented syntax of CGI.pm.

Maybe someone else knows a shorter way to do this ?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives