minhtam2448
Technical User
Hi. I just picked up an interest in PERL and CGI programming and I want to run a little popularity contest within anime characters. Unfortunately, I am unsure of my knowledge within CGI to do so. I have a lot of questions to ask, so please bear with me.
At this point, I am unsure of what to ask, since I believe my questions are more progressive, but I am trying to understand and figure out how to write a CGI program to accept GET and post INPUTS, and compile it in a way so that it adds 1 to the total, in other words, tally votes.
A friend of mine provided me a script that may prove to be very useful. The # comments are written by me to show how much of the script I understand. (The ones colored in red are not part of the script, as comments shouldn't be written between the curly brackets.
sub GetFormInput # calls the subroutine
{
(*fval) = @_ if @_ ; # ???
local ($buf); # defines variables
if ($ENV{'REQUEST_METHOD'} eq 'POST')
{
read(STDIN,$buf,$ENV{'CONTENT_LENGTH'}); # reads input, stores it in variable (?), takes the Content Length environmental variable
}
else
{
$buf=$ENV{'QUERY_STRING'}; # variable equals the query string
}
if ($buf eq "")
{
return 0 ; # if buf variable is empty, return a zero value or false
}
else # From here to the end is where I get lost
{
@fval=split(/&/,$buf);
foreach $i (0 .. $#fval)
{
($name,$val)=split (/=/,$fval[$i],2);
$val=~tr/+/ /;
$val=~ s/%(..)/pack("c",hex($1))/ge;
$name=~tr/+/ /;
$name=~ s/%(..)/pack("c",hex($1))/ge;
if (!defined($FORM{$name}))
{
$FORM{$name}=$val;
}
else
{
$FORM{$name} .= ",$val";
#if you want multi-selects to goto into an array change to:
#$field{$name} .= "\0$val";
}
}
}
return 1;
}
So I guess my first few questions are thus:
1. Am I understanding this script correctly thus far?
2. Can anybody explain everything from where I don't understand the script to the "return 1" command?
At this point, I am unsure of what to ask, since I believe my questions are more progressive, but I am trying to understand and figure out how to write a CGI program to accept GET and post INPUTS, and compile it in a way so that it adds 1 to the total, in other words, tally votes.
A friend of mine provided me a script that may prove to be very useful. The # comments are written by me to show how much of the script I understand. (The ones colored in red are not part of the script, as comments shouldn't be written between the curly brackets.
sub GetFormInput # calls the subroutine
{
(*fval) = @_ if @_ ; # ???
local ($buf); # defines variables
if ($ENV{'REQUEST_METHOD'} eq 'POST')
{
read(STDIN,$buf,$ENV{'CONTENT_LENGTH'}); # reads input, stores it in variable (?), takes the Content Length environmental variable
}
else
{
$buf=$ENV{'QUERY_STRING'}; # variable equals the query string
}
if ($buf eq "")
{
return 0 ; # if buf variable is empty, return a zero value or false
}
else # From here to the end is where I get lost
{
@fval=split(/&/,$buf);
foreach $i (0 .. $#fval)
{
($name,$val)=split (/=/,$fval[$i],2);
$val=~tr/+/ /;
$val=~ s/%(..)/pack("c",hex($1))/ge;
$name=~tr/+/ /;
$name=~ s/%(..)/pack("c",hex($1))/ge;
if (!defined($FORM{$name}))
{
$FORM{$name}=$val;
}
else
{
$FORM{$name} .= ",$val";
#if you want multi-selects to goto into an array change to:
#$field{$name} .= "\0$val";
}
}
}
return 1;
}
So I guess my first few questions are thus:
1. Am I understanding this script correctly thus far?
2. Can anybody explain everything from where I don't understand the script to the "return 1" command?