in reply to Re^2: Run Perl function using href
in thread Run Perl function using href

Just trying to understand your question.

It looks like you want to display a link, that when clicked, will call up some perl code (a specific function).

If this is the case (and you are doing simple CGI), the href target will be the perl code file. You can pass additional parameters to the code file to call specific functions.

Assuming your code is called cgi2.pl, and your cgi directory is "cgi-bin", and the function name is myfunc2, your initial page should have the href (statically or dynamically generated) to say:

<a href="/cgi-bin/cgi2.pl?pleasecall=myfunc2&param1=one&param2=two"> +Click here to call func</a>
Now your cgi2.pl needs code like this (All this gets much nicer, if you "use CGI;"):
my %param; # Access the Query String Data if (length ($ENV{'QUERY_STRING'}) > 0){ my @pairs = split(/&/, $ENV{'QUERY_STRING'}); foreach my $pair (@pairs){ my ($name, $value) = split(/=/, $pair); $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg +; $param{$name} = $value; } } # Find function, and call it with params .. if ($param{pleasecall} eq "myfunc2"){ myfunc2 ($param{param1}, $param{param2}); }

            "XML is like violence: if it doesn't solve your problem, use more."

Replies are listed 'Best First'.
Re^4: Run Perl function using href
by chromatic (Archbishop) on Aug 15, 2011 at 22:57 UTC
    All this gets much nicer, if you "use CGI;"

    CGI has far fewer bugs, too.