Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hyperlink calls subroutine instead a script

Status
Not open for further replies.

imad77

Instructor
Oct 18, 2008
97
CA
Hi,

I developed a Perl script where we can click on a hyperlink and it calls another script with a parameter file.

print qq~ <a href="download.pl?file=$file">$file</a><br>
~;

I want to use a hyperlink calling a subroutine with this parameter instead an external script.


Is it a way to perform these actions in Perl?

Thanks a lot.
 
There's not... not in the way you're thinking.

When you request a Perl/CGI script from the webserver, the server executes the script on the server's side, the script writes out the HTML code or whatever, then exits and the browser gets to see what the script wrote. So by the time the page has finished loading, the script that ran on the server is no longer running; it's come to a stop. So you can't have a hyperlink on the page provoke a subroutine in your CGI script because your CGI script is no longer executing.

The closest you'll be able to get will be to have your CGI script also print out some JavaScript source code as part of the web page, and have your hyperlink provoke the JavaScript function. If the function will require any server-side changes (modifying files, reading files that aren't accessible over the web, or anything that client-side JavaScript isn't allowed to do), you'll need to use Ajax and then create a separate Perl/CGI script (or modify your existing script) so that it provides a much simplified API that the JavaScript can provoke, which would do the server-side work requested by the JavaScript and optionally print some kind of feedback so that the JavaScript can confirm whether or not the operation was successful.

It's a complicated solution and will require a lot of hands-on tinkering and attention to detail (unless there's some kind of library that highly simplifies this, but I'm not aware of any).

-------------
Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top