in reply to Calling a sub-routine in CGI

Hi Anonymous Monk,

Hmmm... Yes, it easy, depending on what you want to do. Are you

a) Trying to execute what ever is in &toggle_on and put the output of that text in your A HREF command, or are you

b) Trying to get &toggle_on to execute when you click the ON hyperlink? It almost looks like this is what you're trying to do. If so, you're going the wrong way.

Solution A

print "<a href=" . &toggle_on . ">ON</a>";

Solution B

#get the UNWEB procedure in here $FORM=&unweb; if($FORM{action} eq "toggleon") { &toggle_on; } else { print "<a href=\"?action=toggleon\">ON</a>\n"; }
This is a very simplified way of going.

Replies are listed 'Best First'.
Re: Re: Calling a sub-routine in CGI
by Anonymous Monk on Aug 09, 2002 at 11:33 UTC
    I'm sorry, but I'm still learning...Where can I learn more about UNWEB? Thanks
      Here's what you need...
      sub unweb { if($ENV{QUERY_STRING} eq "") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{QUERY_STRING}; } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/~!/ ~!/g; $FORM{$name} = $value; } return %FORM; }
      Have a look at cgi101. That's where I started with CGIs.