Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to define in Perl that an HTML link is clicked.

    Hello

    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:

    Code:
    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?

  • #2
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    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:

    Code:
    <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:

    Code:
    <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.

  • #3
    New Coder
    Join Date
    Jun 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    The name of the module is CGI.

    http://perldoc.perl.org/CGI.html

    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:

    Code:
    <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

    Code:
    #!/usr/bin/perl
    use CGI qw/:standard/;
    my $query = param('name');
    print header(),start_html();
    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:

    http://www.yourserver.com/test.html

    click the link.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •