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."


In reply to Re^3: Run Perl function using href by NetWallah
in thread Run Perl function using href by rainmanh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.