Ultimater
02-23-2005, 10:16 PM
Hey, my PERL code is not working at all!
I'm running the game JS Falcon, when the user gets a high score,
I want the user to click my button to submit the highscore.
My PERL is supposed to read the value of the "SCORE"
and write it to a .JS file that is also located in my cgi-bin.
HERE'S the submiting layer:
(The DIV emerges via JavaScript when the Highscore is beaten.)
<DIV ID="sendLay" STYLE='position:absolute; left:48; top:-1000'>
<FORM NAME="HIS" method="post" action="../cgi-bin/falcon_hs.pl">
<INPUT NAME="SCORE" type="hidden" size="20">
<INPUT NAME="B1" type="submit" value="Send HIGH SCORE" onSubmit="reload(true)">
</FORM>
</DIV>
The URL of the above segment of my game is:
http://ultimiacian.tripod.com/games/JSFalcon.html (http://ultimiacian.tripod.com/games/JSFalcon.html)
Then I have a PERL file in the current URL:
http://ultimiacian.tripod.com/cgi-bin/falcon_hs.pl
The PERL code reads:
use ReadParse;
&ReadParse;
$jsfile="falcon_hs.js";
$in{'SCORE'} =~ s/[^0-9a-z]//g;
open(DAFILE, "<<$jsfile");
print DAFILE "SCORE=54000";
close(DAFILE);
The ReadParse.pm is:
sub ReadParse {
local (*in) = @_ if @_;
local ($i, $key, $val);
# Read in text
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
}
@in = split(/[&;]/,$in);
foreach $i (0 .. $#in) {
# Convert plus's to spaces
$in[$i] =~ s/\+/ /g;
# Split into key and value.
($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
# Convert %XX from hex numbers to alphanumeric
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
# Associate key and value
$in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
$in{$key} .= $val;
}
return scalar(@in);
}
1
I'm running the game JS Falcon, when the user gets a high score,
I want the user to click my button to submit the highscore.
My PERL is supposed to read the value of the "SCORE"
and write it to a .JS file that is also located in my cgi-bin.
HERE'S the submiting layer:
(The DIV emerges via JavaScript when the Highscore is beaten.)
<DIV ID="sendLay" STYLE='position:absolute; left:48; top:-1000'>
<FORM NAME="HIS" method="post" action="../cgi-bin/falcon_hs.pl">
<INPUT NAME="SCORE" type="hidden" size="20">
<INPUT NAME="B1" type="submit" value="Send HIGH SCORE" onSubmit="reload(true)">
</FORM>
</DIV>
The URL of the above segment of my game is:
http://ultimiacian.tripod.com/games/JSFalcon.html (http://ultimiacian.tripod.com/games/JSFalcon.html)
Then I have a PERL file in the current URL:
http://ultimiacian.tripod.com/cgi-bin/falcon_hs.pl
The PERL code reads:
use ReadParse;
&ReadParse;
$jsfile="falcon_hs.js";
$in{'SCORE'} =~ s/[^0-9a-z]//g;
open(DAFILE, "<<$jsfile");
print DAFILE "SCORE=54000";
close(DAFILE);
The ReadParse.pm is:
sub ReadParse {
local (*in) = @_ if @_;
local ($i, $key, $val);
# Read in text
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
}
@in = split(/[&;]/,$in);
foreach $i (0 .. $#in) {
# Convert plus's to spaces
$in[$i] =~ s/\+/ /g;
# Split into key and value.
($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
# Convert %XX from hex numbers to alphanumeric
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
# Associate key and value
$in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
$in{$key} .= $val;
}
return scalar(@in);
}
1