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

many thanks for your replies. I went through manuals and they use to go through a simple href pointer but never got an approximation on how to execute a function within the perl command recalled by href which was my problem, and I did not want to include more forms as I already got my share of them to run this application.

Replies are listed 'Best First'.
Re^3: Run Perl function using href
by NetWallah (Canon) on Aug 15, 2011 at 22:22 UTC
    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."

      All this gets much nicer, if you "use CGI;"

      CGI has far fewer bugs, too.

Re^3: Run Perl function using href
by ww (Archbishop) on Aug 15, 2011 at 15:30 UTC
    You do understand, don't you, that a browser -- by itself -- can NOT execute a perl function?

    ... and which "manuals" did you go through? Your response seems to suggest that you must have skipped those suggested in Re: Run Perl function using href.

      There is no need for an aggressive behaviour neither a need to make feel bad newcomers