View Full Version : How to define in Perl that an HTML link is clicked.
06-15-2009, 01:46 PM
I have a Perl script (mixed with HTML) which outputs a number of HTML links.
Each link corresponds to a certain amount of data from a text file. What I'm trying to do is create an if statement saying that:
If (link A is clicked ) print "$data1";
elsif (link B is clicked) print "$data2";
Does anyone know how to make Perl understand that a particular link is clicked. Is this possible?
Any suggestions please?
06-15-2009, 09:21 PM
perl has no idea what a hyperlink is nor can it tell one link from another. YOu have to code you links with some paramaters perl can use to know what it should do, with a link that is the query string and name/value pairs, something like:
<a href="foo.cgi?age=young&name=kevin">click here</a>
your script collects the query string and parses it into varaibles. So "age" and "name" are the static part of the equation but the values can change:
<a href="foo.cgi?age=old&name=fishmonger">click here</a>
Perl comes with the CGI module that is used to make the process fairly painless for the programmer but the learning curve will seem steep if you're a total newbie to CGI scripting.
06-16-2009, 06:02 PM
Thanks for the tip KevinADC
By the way what is the name of the module you are talking about? I'm relatively new to cgi scripting but I would like to give it a go.
06-16-2009, 07:24 PM
The name of the module is CGI.
I know.... its a lot of reading. I've been reading that document for years and I still dicover new tid-bits. If you are totally new to CGI this is going to be a learning process so don't get discouraged if it seems like alien technology to you right now. Start simple. Make an html page with this link:
<a href="cgi-bin/test.pl?name=goude">Click here</a>
copy and paste this code into a plain text file and save it as test.pl
use CGI qw/:standard/;
my $query = param('name');
print "Hello $query!";
Upload it to a webserver (in ASCII or text mode) in the cgi-bin. chmod it to 755 if necessary. See you FTP applications help files for chmod if necessary.
Upload the html file into your webservers root www folder, name it test.html.
Open your web browser and type in the URI of the html document:
click the link.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.