As
DamnDirtyApe has started to allude to, you cannot use a hyperlink to call a subroutine. A perl subroutine is encapsulated within the CGI process. An HTML hyperlink is simply another way of requesting a web "object", where an object can be any manner of hosted files... text/html, images, cgi scripts, etc. However, the execution of said scripts does NOT happen within Apache's process... a separate perl process is started to handle the cgi task; only the output of the script is returned to Apache for output to the requestor (browser).
Assuming you want the script to perform some function as defined by a subroutine, I suggest you create a URL with custom or hidden parameters, which, when read in by the cgi, understands to run the appropriate subroutine. Example:
#/usr/bin/perl -w
use strict;
use CGI qw(:standard);
my $cgi = CGI->new;
if ($cgi->param()) {
if ($cgi->param('toggle_on')) {
&toggle_on;
} elsif ($cgi->param('toggle_off')) {
&toggle_off;
} else {
&default;
}
} else {
# print form
print $cgi->a({href => "/cgi-bin/script.cgi?toggle_on=1"}, "Toggle
+ On");
# print more stuff
}
Hope this helps!
-fp
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.