PDA

View Full Version : Need help with my first perl script


maciel310
07-17-2003, 12:45 AM
Hi all
I am having a little trouble with a code I am in the process of making, and I need a little help. I am kinda new to perl so I am sorry if this is an extremely easy question. The script I am working on, once finished, will take input from a form and update a statistics page for this game I play, showing wins and losses, but whenever I attempt to run this code, I get the following syntax error:

syntax error at writestandings.pl line 14, near "$UserCode) "
syntax error at writestandings.pl line 23, near ")
$Joldwins "
syntax error at writestandings.pl line 25, near ")
$Joldlosses "
syntax error at writestandings.pl line 34, near ")
{"
Execution of writestandings.pl aborted due to compilation errors

Can anyone tell me what is going on? Below is a text version of my code:

Script (http://yugiohstandings.netfirms.com/standings.html)

I would appreciate anyhelp that you could give me

Thanks
--maciel310

ACJavascript
07-17-2003, 03:07 AM
open(Jstandings, " #Opens the file for reading

should be

#Opens the file for reading
open(Jstandings, ");

maciel310
07-17-2003, 08:25 PM
That must have happend when I uploaded it to my server, my host doesnt allow plain text so I converted it to html so that must have messed up some things, Ill attach the file this time.

ACJavascript
07-17-2003, 08:34 PM
If ($FORM{$UserCode} = "Jeremy")

Should be

if($FORM{'nameofFormField'} eq Jeremy)

maciel310
07-18-2003, 01:14 AM
Ok, now all it gives is a 500 message, no reason given...

ACJavascript
07-18-2003, 07:06 PM
if($FORM{$UserCode} eq Jeremy)

the $UsrCode within the form is wrong. Or it will give you errors.

What is $UserCode? I dont see it declared in the script.

maciel310
07-18-2003, 08:11 PM
$UserCode is one of the variables passed on by the form to identify which user is loging in to change their stats, then depending on which user it is, it will check for changes in wins and losses then save the new stats to a text file which will then change some variables on a stats so it will display the current wins and losses automatically. Sorry if I didnt explain this well enough in my original post.

ACJavascript
07-19-2003, 03:53 PM
Okay,,

So $UserCode is definied in the form.

LIke <input type="text" name="userCode"> ??

having $UserCode like that --> ($UserCode)
Tells the script that it is being definied in the script.
As if you had a $UserCode="Jimmy"; in the begining of the script.

If its a form field being checked you should do this
if($FORM{'userCode'} eq "Jimmy"){

maciel310
07-19-2003, 06:42 PM
Ok, thanks for all the help you have given, still some errors tho:

syntax error at writestandings.pl line 24, near ")
$Joldwins "
syntax error at writestandings.pl line 26, near ")
$Joldlosses "
syntax error at writestandings.pl line 45, near ")
{"
syntax error at writestandings.pl line 69, near "}"
Execution of writestandings.pl aborted due to compilation errors.



Updated code attached

ACJavascript
07-23-2003, 12:50 AM
Sorry I havn't replied in a while been really busy with finals. All done now though :D
---

Okay

see here
If ($line = 1)
$Joldwins = $line;
ElseIf ($line = 2)
$Joldlosses = $line;
Else
$Jpoints = $line;

Should be

If ($line == 1){
$Joldwins = $line;
}elsIf ($line == 2){
$Joldlosses = $line;
}else{
$Jpoints = $line;
}

maciel310
07-23-2003, 06:18 AM
Fixed some of the errors, but not all of them :(

Still getting the following errors:

syntax error at writestandings.pl line 23, near "){"
syntax error at writestandings.pl line 25, near "){"
syntax error at writestandings.pl line 31, near "}"


Looks like it has to do with the reading of the text files. It doesnt really matter how the script gets the info from the files, as long as it is able to set the data on each line or between any other seporators to different variables, it will be fine, whatever ends up being easier.

Thanks for all the help you have offered so far, you have been a great help.

Attaching the new script

ACJavascript
07-23-2003, 04:28 PM
Try this,

I noticed that you didn't close some of the open files.

#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@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;
$FORM{$name} = $value;
}

$url = "http://www.site.com";

if($FORM{'UserCode'} eq "Jeremy")
{
open(Jstandings, "JStandings.txt");
#Opens the file for reading
my(@lines) = <Jstandings>;
close(Jstandings);

foreach $line (@lines){
if ($line==1){
$Joldwins=$line;
}elsif($line == 2){
$Joldlosses=$line;
}else{
$Jpoints = $line;
}

}

#makes list
#my($Joldwins, $Joldlosses, $Jpoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0")
{
$JnewWins = $Joldwins;
}
Else
{
$JnewWins = ($Joldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0")
{
$JnewLosses = $Joldlosses;
}
Else
{
$JnewLosses = ($Joldlosses + $FORM{'Losses'});
}

$Jpoints = $JnewWins - $JnewLosses;


close(Jstandings);
#properly closes the file on the server

open(JstandingsOut, ">JStandings.txt");

print JstandingsOut $JnewWins;
print JstandingsOut $JnewLosses;
print JstandingsOut $Jpoints;
#Appends the quoted text to the file

close(JstandinsOut);

print "Location: $url\n\n";
}elseif($FORM{'UserCode'} eq "Anthony"){
open(Astandings, "<AStandings.txt");
#Opens the file for appending
my(@lines) = <Astandings>;
close(Astandings);

foreach $line (@lines)
{
If ($line == 1){
$Aoldwins = $line;
}elsif ($line == 2){
$Aoldlosses = $line;
}else{
$Apoints = $line;
}

}

#makes list
#my($Aoldwins, $Aoldlosses, $Apoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0")
{
$AnewWins = $Aoldwins;
}
Else
{
$AnewWins = ($Aoldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0")
{
$AnewLosses = $Aoldlosses;
}
Else
{
$AnewLosses = ($Aoldlosses + $FORM{'Losses'});
}

$Apoints = $AnewWins - $AnewLosses;


close(Astandings);
#properly closes the file on the server

open(AstandingsOut, ">AStandings.txt");

print AstandingsOut $AnewWins;
print AstandingsOut $AnewLosses;
print AstandingsOut $Apoints;
#Appends the quoted text to the file

close(AstandinsOut);

print "Location: $url\n\n";
}


elseif($FORM{'UserCode'} eq "Steven")
{
open(Sstandings, "<SStandings.txt");
#Opens the file for appending
my(@lines) = <Sstandings>;

foreach $line (@lines)
{
If ($line == 1){
$Soldwins = $line;
}elsIf ($line == 2){
$Soldlosses = $line;
}else{
$Spoints = $line;
}

}


#makes list
#my($Soldwins, $Soldlosses, $Spoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0")
{
$SnewWins = $Soldwins;
}
Else
{
$SnewWins = ($Soldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0")
{
$SnewLosses = $Soldlosses;
}
Else
{
$SnewLosses = ($Soldlosses + $FORM{'Losses'});
}

$Spoints = $SnewWins - $SnewLosses;


close(Sstandings);
#properly closes the file on the server

open(SstandingsOut, ">SStandings.txt");

print SstandingsOut $SnewWins;
print SstandingsOut $SnewLosses;
print SstandingsOut $Spoints;
#Appends the quoted text to the file

close(SstandinsOut);

print "Location: $url\n\n";
}




elseif($FORM{'UserCode'} eq "Kagen")
{
open(Kstandings, "<KStandings.txt");
#Opens the file for appending
my(@lines) = <Kstandings>;

foreach $line (@lines)
{
If ($line == 1){
$Koldwins = $line;
}elsIf ($line == 2){
$Koldlosses = $line;
}else{
$Kpoints = $line;
}

}

#makes list
#my($Koldwins, $Koldlosses, $Kpoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0")
{
$KnewWins = $Koldwins;
}
Else
{
$KnewWins = ($Koldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0")
{
$KnewLosses = $Koldlosses;
}
Else
{
$KnewLosses = ($Koldlosses +$FORM{'Losses'});
}

$Kpoints = $KnewWins - $KnewL

ACJavascript
07-23-2003, 04:29 PM
Try this,

I noticed that you didn't close some of the open files.

#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@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;
$FORM{$name} = $value;
}

$url = "http://www.site.com";

if($FORM{'UserCode'} eq "Jeremy")
{
open(Jstandings, "JStandings.txt");
#Opens the file for reading
my(@lines) = <Jstandings>;
close(Jstandings);

foreach $line (@lines){
if ($line==1){
$Joldwins=$line;
}elsif($line == 2){
$Joldlosses=$line;
}else{
$Jpoints = $line;
}

}

#makes list
#my($Joldwins, $Joldlosses, $Jpoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0")
{
$JnewWins = $Joldwins;
}
Else
{
$JnewWins = ($Joldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0")
{
$JnewLosses = $Joldlosses;
}
Else
{
$JnewLosses = ($Joldlosses + $FORM{'Losses'});
}

$Jpoints = $JnewWins - $JnewLosses;


close(Jstandings);
#properly closes the file on the server

open(JstandingsOut, ">JStandings.txt");

print JstandingsOut $JnewWins;
print JstandingsOut $JnewLosses;
print JstandingsOut $Jpoints;
#Appends the quoted text to the file

close(JstandinsOut);

print "Location: $url\n\n";
}elseif($FORM{'UserCode'} eq "Anthony"){
open(Astandings, "<AStandings.txt");
#Opens the file for appending
my(@lines) = <Astandings>;
close(Astandings);

foreach $line (@lines)
{
If ($line == 1){
$Aoldwins = $line;
}elsif ($line == 2){
$Aoldlosses = $line;
}else{
$Apoints = $line;
}

}

#makes list
#my($Aoldwins, $Aoldlosses, $Apoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0")
{
$AnewWins = $Aoldwins;
}
Else
{
$AnewWins = ($Aoldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0")
{
$AnewLosses = $Aoldlosses;
}
Else
{
$AnewLosses = ($Aoldlosses + $FORM{'Losses'});
}

$Apoints = $AnewWins - $AnewLosses;


close(Astandings);
#properly closes the file on the server

open(AstandingsOut, ">AStandings.txt");

print AstandingsOut $AnewWins;
print AstandingsOut $AnewLosses;
print AstandingsOut $Apoints;
#Appends the quoted text to the file

close(AstandinsOut);

print "Location: $url\n\n";
}


elseif($FORM{'UserCode'} eq "Steven")
{
open(Sstandings, "<SStandings.txt");
#Opens the file for appending
my(@lines) = <Sstandings>;

foreach $line (@lines)
{
If ($line == 1){
$Soldwins = $line;
}elsIf ($line == 2){
$Soldlosses = $line;
}else{
$Spoints = $line;
}

}


#makes list
#my($Soldwins, $Soldlosses, $Spoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0")
{
$SnewWins = $Soldwins;
}
Else
{
$SnewWins = ($Soldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0")
{
$SnewLosses = $Soldlosses;
}
Else
{
$SnewLosses = ($Soldlosses + $FORM{'Losses'});
}

$Spoints = $SnewWins - $SnewLosses;


close(Sstandings);
#properly closes the file on the server

open(SstandingsOut, ">SStandings.txt");

print SstandingsOut $SnewWins;
print SstandingsOut $SnewLosses;
print SstandingsOut $Spoints;
#Appends the quoted text to the file

close(SstandinsOut);

print "Location: $url\n\n";
}




elseif($FORM{'UserCode'} eq "Kagen")
{
open(Kstandings, "<KStandings.txt");
#Opens the file for appending
my(@lines) = <Kstandings>;

foreach $line (@lines)
{
If ($line == 1){
$Koldwins = $line;
}elsIf ($line == 2){
$Koldlosses = $line;
}else{
$Kpoints = $line;
}

}

#makes list
#my($Koldwins, $Koldlosses, $Kpoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0")
{
$KnewWins = $Koldwins;
}
Else
{
$KnewWins = ($Koldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0")
{
$KnewLosses = $Koldlosses;
}
Else
{
$KnewLosses = ($Koldlosses +$FORM{'Losses'});
}

$Kpoints = $KnewWins - $KnewLosses;

maciel310
07-23-2003, 06:50 PM
Nope, still not working, I had closed those files, just not right away, I closed them right before I opened them again to edit.

I messed with the code a little to see if I could get it to work, but no luck. Ill attach the new code.

Oh yeah, and one more thing, could these errors be coming about by an impropper chmod? What should the txt files be chmodded to that will allow them to be read and written to by the script?

Same syntax errors...

ACJavascript
07-23-2003, 07:05 PM
the txt files CHMOD should not be the problem. But just incase CHMOD them to 666.

try this
-------
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@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;
$FORM{$name} = $value;
}

$url = "http://www.site.com";

if($FORM{'UserCode'} eq "Jeremy")
{
open(Jstandings, "JStandings.txt");
#Opens the file for reading
my(@lines) = <Jstandings>;
close(Jstandings);

foreach $line (@lines){
if($line==1){
$Joldwins=$line;
}elsif($line==2){
$Joldlosses = $line;
}else{
$Jpoints = $line;
}

}

#makes list
#my($Joldwins, $Joldlosses, $Jpoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0"){
$JnewWins = $Joldwins;
}else{
$JnewWins =($Joldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0"){
$JnewLosses = $Joldlosses;
}else{
$JnewLosses = ($Joldlosses + $FORM{'Losses'});
}

$Jpoints = $JnewWins - $JnewLosses;



#properly closes the file on the server

open(JstandingsOut,">JStandings.txt");

print JstandingsOut $JnewWins;
print JstandingsOut $JnewLosses;
print JstandingsOut $Jpoints;
#Appends the quoted text to the file

close(JstandinsOut);

print "Location: $url\n\n";
}

elseif($FORM{'UserCode'} eq "Anthony")
{
open(Astandings, "<AStandings.txt");
#Opens the file for appending
my(@lines) = <Astandings>;
close(Astandings);

foreach $line(@lines){
if($line==1){
$Aoldwins=$line;
}elsif ($line==2){
$Aoldlosses = $line;
}else{
$Apoints = $line;
}

}

#makes list
#my($Aoldwins, $Aoldlosses, $Apoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0"){
$AnewWins = $Aoldwins;
}else{
$AnewWins = ($Aoldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0"){
$AnewLosses = $Aoldlosses;
}else{
$AnewLosses = ($Aoldlosses + $FORM{'Losses'});
}

$Apoints = $AnewWins - $AnewLosses;



#properly closes the file on the server

open(AstandingsOut, ">AStandings.txt");

print AstandingsOut $AnewWins;
print AstandingsOut $AnewLosses;
print AstandingsOut $Apoints;
#Appends the quoted text to the file

close(AstandinsOut);

print "Location: $url\n\n";
}


elsif($FORM{'UserCode'} eq "Steven")
{
open(Sstandings, "<SStandings.txt");
#Opens the file for appending
my(@lines) = <Sstandings>;
close(Sstandings);

foreach $line(@lines){
if ($line==1){
$Soldwins = $line;
}elsif ($line==2){
$Soldlosses = $line;
}else{
$Spoints = $line;
}

}


#makes list
#my($Soldwins, $Soldlosses, $Spoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0")
{
$SnewWins = $Soldwins;
}else{
$SnewWins = ($Soldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0")
{
$SnewLosses = $Soldlosses;
}else{
$SnewLosses = ($Soldlosses + $FORM{'Losses'});
}

$Spoints = $SnewWins - $SnewLosses;



#properly closes the file on the server

open(SstandingsOut, ">SStandings.txt");

print SstandingsOut $SnewWins;
print SstandingsOut $SnewLosses;
print SstandingsOut $Spoints;
#Appends the quoted text to the file

close(SstandinsOut);

print "Location: $url\n\n";
}




elseif($FORM{'UserCode'} eq "Kagen")
{
open(Kstandings, "<KStandings.txt");
#Opens the file for appending
my(@lines) = <Kstandings>;
close(Kstandings);

foreach $line(@lines){
if($line==1){
$Koldwins=$line;
}elsif($line==2){
$Koldlosses = $line;
}else{
$Kpoints = $line;
}

}

#makes list
#my($Koldwins, $Koldlosses, $Kpoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0")
{
$KnewWins = $Koldwins;
}else{
$KnewWins = ($Koldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0")
{
$KnewLosses = $Koldlosses;
}else{
$KnewLosses = ($Koldlosses +$FORM{'Losses'});
}

$Kpoints = $KnewWins - $KnewLosses;



#properly closes the file on the server

open(KstandingsOut, ">KStandings.txt");

print KstandingsOut $KnewWins;
print KstandingsOut $KnewLosses;
print KstandingsOut $Kpoints;
#Appends the quoted text to the file

close(KstandinsOut);

print "Location: $url\n\n";
}else{
print "There was an error with your PassCode, please hit back and try again";
}




exit;

maciel310
07-23-2003, 07:26 PM
That got rid of the old syntax errors, but a couple new ones came up, allwell, just got to take it one step at a time

The new syntax errors:

syntax error at writestandings.pl line 68, near ")
{"
syntax error at writestandings.pl line 117, near "}"

Same code as you posted so no need to attach it again.

ACJavascript
07-24-2003, 09:17 PM
hehe baby steps lol
-------
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@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;
$FORM{$name} = $value;
}

$url = "http://www.site.com";

if($FORM{'UserCode'} eq "Jeremy")
{
open(Jstandings, "JStandings.txt");
#Opens the file for reading
my(@lines) = <Jstandings>;
close(Jstandings);

foreach $line (@lines){
if($line==1){
$Joldwins=$line;
}elsif($line==2){
$Joldlosses = $line;
}else{
$Jpoints = $line;
}

}

#makes list
#my($Joldwins, $Joldlosses, $Jpoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0"){
$JnewWins = $Joldwins;
}else{
$JnewWins =($Joldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0"){
$JnewLosses = $Joldlosses;
}else{
$JnewLosses = ($Joldlosses + $FORM{'Losses'});
}

$Jpoints = $JnewWins - $JnewLosses;



#properly closes the file on the server

open(JstandingsOut,">JStandings.txt");

print JstandingsOut $JnewWins;
print JstandingsOut $JnewLosses;
print JstandingsOut $Jpoints;
#Appends the quoted text to the file

close(JstandinsOut);

print "Location: $url\n\n";

}elsif($FORM{'UserCode'} eq "Anthony"){
open(Astandings, "<AStandings.txt");
#Opens the file for appending
my(@lines) = <Astandings>;
close(Astandings);

foreach $line(@lines){
if($line==1){
$Aoldwins=$line;
}elsif ($line==2){
$Aoldlosses = $line;
}else{
$Apoints = $line;
}

}

#makes list
#my($Aoldwins, $Aoldlosses, $Apoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0"){
$AnewWins = $Aoldwins;
}else{
$AnewWins = ($Aoldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0"){
$AnewLosses = $Aoldlosses;
}else{
$AnewLosses = ($Aoldlosses + $FORM{'Losses'});
}

$Apoints = $AnewWins - $AnewLosses;



#properly closes the file on the server

open(AstandingsOut, ">AStandings.txt");

print AstandingsOut $AnewWins;
print AstandingsOut $AnewLosses;
print AstandingsOut $Apoints;
#Appends the quoted text to the file

close(AstandinsOut);

print "Location: $url\n\n";
}elsif($FORM{'UserCode'} eq "Steven"){
open(Sstandings, "<SStandings.txt");
#Opens the file for appending
my(@lines) = <Sstandings>;
close(Sstandings);

foreach $line(@lines){
if ($line==1){
$Soldwins = $line;
}elsif ($line==2){
$Soldlosses = $line;
}else{
$Spoints = $line;
}

}


#makes list
#my($Soldwins, $Soldlosses, $Spoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0")
{
$SnewWins = $Soldwins;
}else{
$SnewWins = ($Soldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0")
{
$SnewLosses = $Soldlosses;
}else{
$SnewLosses = ($Soldlosses + $FORM{'Losses'});
}

$Spoints = $SnewWins - $SnewLosses;



#properly closes the file on the server

open(SstandingsOut, ">SStandings.txt");

print SstandingsOut $SnewWins;
print SstandingsOut $SnewLosses;
print SstandingsOut $Spoints;
#Appends the quoted text to the file

close(SstandinsOut);

print "Location: $url\n\n";
}




elseif($FORM{'UserCode'} eq "Kagen")
{
open(Kstandings, "<KStandings.txt");
#Opens the file for appending
my(@lines) = <Kstandings>;
close(Kstandings);

foreach $line(@lines){
if($line==1){
$Koldwins=$line;
}elsif($line==2){
$Koldlosses = $line;
}else{
$Kpoints = $line;
}

}

#makes list
#my($Koldwins, $Koldlosses, $Kpoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0")
{
$KnewWins = $Koldwins;
}else{
$KnewWins = ($Koldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0")
{
$KnewLosses = $Koldlosses;
}else{
$KnewLosses = ($Koldlosses +$FORM{'Losses'});
}

$Kpoints = $KnewWins - $KnewLosses;



#properly closes the file on the server

open(KstandingsOut, ">KStandings.txt");

print KstandingsOut $KnewWins;
print KstandingsOut $KnewLosses;
print KstandingsOut $Kpoints;
#Appends the quoted text to the file

close(KstandinsOut);

print "Location: $url\n\n";
}else{
print "There was an error with your PassCode, please hit back and try again";
}




exit;

maciel310
07-25-2003, 06:26 PM
Almost there, looks like whatever your doing for the previouse name cases need to be done to all of them, new error:

syntax error at writestandings.pl line 173, near ")
{"
syntax error at writestandings.pl line 224, near "}"

This is in the last name so this might be the end of the errors :):):)

Oh yea, almost forgot, I need to add one more name to the script, but Ill just copy it from one of the ones that we already fixed and hopefully it will work without any need to change anything.


Attaching the script with the new person:

ACJavascript
07-25-2003, 06:45 PM
It does look like the last of the errors hehe :D
-----------
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@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;
$FORM{$name} = $value;
}

$url = "http://www.site.com";

if($FORM{'UserCode'} eq "Jeremy")
{
open(Jstandings, "JStandings.txt");
#Opens the file for reading
my(@lines) = <Jstandings>;
close(Jstandings);

foreach $line (@lines){
if($line==1){
$Joldwins=$line;
}elsif($line==2){
$Joldlosses = $line;
}else{
$Jpoints = $line;
}

}

#makes list
#my($Joldwins, $Joldlosses, $Jpoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0"){
$JnewWins = $Joldwins;
}else{
$JnewWins =($Joldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0"){
$JnewLosses = $Joldlosses;
}else{
$JnewLosses = ($Joldlosses + $FORM{'Losses'});
}

$Jpoints = $JnewWins - $JnewLosses;



#properly closes the file on the server

open(JstandingsOut,">JStandings.txt");

print JstandingsOut $JnewWins;
print JstandingsOut $JnewLosses;
print JstandingsOut $Jpoints;
#Appends the quoted text to the file

close(JstandinsOut);

print "Location: $url\n\n";

}elsif($FORM{'UserCode'} eq "Anthony"){
open(Astandings, "<AStandings.txt");
#Opens the file for appending
my(@lines) = <Astandings>;
close(Astandings);

foreach $line(@lines){
if($line==1){
$Aoldwins=$line;
}elsif($line==2){
$Aoldlosses = $line;
}else{
$Apoints = $line;
}

}

#makes list
#my($Aoldwins, $Aoldlosses, $Apoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0"){
$AnewWins = $Aoldwins;
}else{
$AnewWins = ($Aoldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0"){
$AnewLosses = $Aoldlosses;
}else{
$AnewLosses = ($Aoldlosses + $FORM{'Losses'});
}

$Apoints = $AnewWins - $AnewLosses;



#properly closes the file on the server

open(AstandingsOut, ">AStandings.txt");

print AstandingsOut $AnewWins;
print AstandingsOut $AnewLosses;
print AstandingsOut $Apoints;
#Appends the quoted text to the file

close(AstandinsOut);

print "Location: $url\n\n";
}elsif($FORM{'UserCode'} eq "Steven"){
open(Sstandings, "<SStandings.txt");
#Opens the file for appending
my(@lines) = <Sstandings>;
close(Sstandings);

foreach $line(@lines){
if($line==1){
$Soldwins = $line;
}elsif ($line==2){
$Soldlosses = $line;
}else{
$Spoints = $line;
}

}


#makes list
#my($Soldwins, $Soldlosses, $Spoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0"){
$SnewWins = $Soldwins;
}else{
$SnewWins = ($Soldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0"){
$SnewLosses = $Soldlosses;
}else{
$SnewLosses = ($Soldlosses + $FORM{'Losses'});
}

$Spoints = $SnewWins - $SnewLosses;



#properly closes the file on the server

open(SstandingsOut, ">SStandings.txt");

print SstandingsOut $SnewWins;
print SstandingsOut $SnewLosses;
print SstandingsOut $Spoints;
#Appends the quoted text to the file

close(SstandinsOut);

print "Location: $url\n\n";
}elsif($FORM{'UserCode'} eq "Kagen"){
open(Kstandings, "<KStandings.txt");
#Opens the file for appending
my(@lines) = <Kstandings>;
close(Kstandings);

foreach $line(@lines){
if($line==1){
$Koldwins=$line;
}elsif($line==2){
$Koldlosses = $line;
}else{
$Kpoints = $line;
}

}

#makes list
#my($Koldwins, $Koldlosses, $Kpoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0"){
$KnewWins = $Koldwins;
}else{
$KnewWins = ($Koldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0"){
$KnewLosses = $Koldlosses;
}else{
$KnewLosses = ($Koldlosses +$FORM{'Losses'});
}

$Kpoints = $KnewWins - $KnewLosses;



#properly closes the file on the server

open(KstandingsOut, ">KStandings.txt");

print KstandingsOut $KnewWins;
print KstandingsOut $KnewLosses;
print KstandingsOut $Kpoints;
#Appends the quoted text to the file

close(KstandinsOut);

print "Location: $url\n\n";
}elsif($FORM{'UserCode'} eq "George"){
open(Gstandings, "<GStandings.txt");
#Opens the file for appending
my(@lines) = <Gstandings>;
close(Gstandings);

foreach $line(@lines){
if($line==1){
$Goldwins=$line;
}elsif($line==2){
$Goldlosses = $line;
}else{
$Gpoints = $line;
}

}

#makes list
#my($Goldwins, $Goldlosses, $Gpoints);
#assigns each line a variable(I hope)
if($FORM{'Wins'} eq "0"){
$GnewWins = $Goldwins;
}else{
$GnewWins = ($Goldwins + $FORM{'Wins'});
}


if($FORM{'Losses'} eq "0"){
$GnewLosses = $Goldlosses;
}else{
$GnewLosses = ($Goldlosses + $FORM{'Losses'});
}

$Gpoints = $GnewWins - $GnewLosses;



#properly closes the file on the server

open(GstandingsOut, ">GStandings.txt");

print GstandingsOut $GnewWins;
print GstandingsOut $GnewLosses;
print GstandingsOut $Gpoints;
#Appends the quoted text to the file

close(GstandinsOut);

print "Location: $url\n\n";

}else{
print "There was an error with your PassCode, please hit back and try again";
}




exit;

maciel310
07-25-2003, 07:06 PM
Its working :D :D :D

The only thing is the final else that is supposed to write an error doesn't work, but I think I know what is wrong, and it doesnt really matter if that doesnt work, at least the rest of the script is woking fine.

Thank you for your help, probably would have taken me forever to find those syntax errors by my self.

Looks like there were a couple small errors that didnt show up in syntax errors, but I got them, Ill go ahead and upload the fully working script in case anyone wants to look at it for reference.

Thanks again for your help with this script

ACJavascript
07-25-2003, 07:12 PM
ALRIGHT!!!! :D:D:D

Glad to help Good luck!

maciel310
07-25-2003, 07:41 PM
Now I have some problem with the displaying of the stats...

What I have is a perl page that has a table in it with the wins losses and points in it that gets its variables by calling the txt files exactly like in the script, then puts them in their respective places on the table, but the script is leaving some of the cells blank for some reason. I will attach a txt file with the script of the page in it.

maciel310
07-25-2003, 11:36 PM
Ok, I found out what was wrong, but Im not sure how to fix it...

When I was trying to get the value of each line from the script, I used:

foreach $line (@lines){
if($line==1){
$Joldwins=$line;
}elsif($line==2){
$Joldlosses = $line;
}else{
$Jpoints = $line;
}

}


Which will just assign those variables to the line number, not the contents of the line, thus making it mess up, now what I need to do is make it set those variables to what is on the line,not the line number, can anyone tell me how to do this?

maciel310
07-26-2003, 02:15 AM
Tried to fix it, now giving the following errors:

syntax error at stats.pl line 11, near "$Joldlosses"
syntax error at stats.pl line 20, near "$Aoldlosses"
syntax error at stats.pl line 29, near "$Soldlosses"
syntax error at stats.pl line 38, near "$Koldlosses"
syntax error at stats.pl line 47, near "$Goldlosses"
Execution of stats.pl aborted due to compilation errors.

I tried opening each part of the array seperately by putting in
$Joldwins=$line[0]
$Joldlosses=$line[1]
$Jpoints=$line[2]
after I set the array to the text file, but it gave the above errors
Any ideas what I did wrong?

Attaching the new stats page

maciel310
07-26-2003, 06:48 PM
Ok, I finally got rid of all the errors! No more that I can find. Thanks for helping

ACJavascript
07-28-2003, 04:16 PM
So is the script writting the correct info to the page? or are you stil working on that one?

maciel310
07-28-2003, 05:37 PM
Every thing is working fine, writing correctly, reading correctly, everything is working in perfect condition. What happend is when I had the
IF (wins = 0){
newwins=oldwins
}
when it copied the old info over it also copied the newline, making it get one off, and I didnt even need that if statement because 1+0 still equals 1. So I took that out and now it will write, read, and print just fine, thanks for asking tho.

ACJavascript
07-28-2003, 07:43 PM
GREAT:thumbsup:

So when can we see an online example??? :D

maciel310
07-28-2003, 08:09 PM
Right now, I have it up and running, just go here (http://anthonys-test-page.netfirms.com/cgi-bin/stats.pl) for the stats page and HERE (http://anthonys-test-page.netfirms.com/index.html) for the actual updater page. The stats page only e-mails the a message to the email stated in the stats page(user@site.com on the page up now) with the wins losses and other stuff so the person running the site can go to the updater page, which is pw protected, and change the info. The password for it is password if any of you want to check it out.

maciel310
07-28-2003, 08:56 PM
Ok, the other people in my group wanted me to implement a ranking system so it would automatically put the persons rank next to their name, and I was wondering if there was an easier way to do this than a bunch of if statements, because if there is it would make my life alot easier. If there is, how would I do it? I want to rank by the points column, and it doesnt matter if it arranges them in order or not, they just wanted a ranking. Thanks for any help, even if it is telling me that I have to do it the hard way...:eek:

ACJavascript
07-28-2003, 10:47 PM
mmmmm,, rankings as in 1-10 points = GOod,, 11-35 = Alright

Like that?

maciel310
07-28-2003, 10:52 PM
No, rankings that change depending on what how your doing compaired to the rest of the people on the chart, like the person with the most ammount of points is #1, the next person is #2, and so on.
I have set up an add on that will allow me to do it manually whenever I update the wins/losses, but if you could tell me how to make it do that automatically, that would be great.

ACJavascript
07-28-2003, 10:56 PM
Well I would do this.

create an all new database (i think you are using txt files)

and create the users names and there points and rank. like so

Name|points|rank

then everytime someone wins or losses have the database pulled up and checked with the user makeing the additions.
If the user goes over the any of the ponts there just replace them with the other user.

That should do the trick

maciel310
07-28-2003, 11:06 PM
I have made a new file similar to that but I am not sure how I would have it automatically sort without having to do a bunch of if statements, I was hoping there was somesort of built in perl funtion or something that would automatically check and sort for me.

What I have will work for now, it wont be hard to update the ranks. What I did was I made another form on the updater page with 5 dropdown boxes with the names of the person right beside it, then I just enter in what rank everyone is at and click submit, which will pass it on and update the ranks file, taking very little time to do.

If there is somesort of built in perl function that will do it automatically, then Ill go ahead and use that, but I think I would rather do it on my own if it means saving myself from having to program all those if statements, which if you think about it there would be a few to have to do.

maciel310
07-29-2003, 02:06 AM
I just tried to setup my stats page to automatically order the table by rank but I ended up getting the following error messages:

syntax error at stats.pl line 163, near "<p> <center><font size=""
BEGIN not safe after errors--compilation aborted at stats.pl line 273.

I guess Im not as done with the script as I thought...

Attaching the stats page script


Accidentally put @'s instead of $'s when I was calling from the arrays, didnt change the error message though, updated script attached.

ACJavascript
07-30-2003, 03:34 PM
huh im not sure why that would be giving an error. Try this
instead of print qq(
put

print <<EOF;

and at the end were ); is
put - EOF

try that

maciel310
07-30-2003, 06:09 PM
Nope, same error. The print qq( was working before on all of my previous scripts, and I believe they all had that same exact line in them also. The only things I changed between the scripts inside the actual HTML part of it was adding an extra table, and using the parts of the arrays instead of actual variables, but those things shouldnt make a difference. Only thing I can think of is if the error is somewhere else and just not showing up until the first line of the HTML part.

ACJavascript
07-30-2003, 06:59 PM
I think I found it

on the last if statment before you write out the html i found this

@rank5=("George", "5"", $Goldwins, $Goldlosses, $Gpoints, $Gtitles);

Notice the 5 has to quote marks should be only one.

@rank5=("George", "5", $Goldwins, $Goldlosses, $Gpoints, $Gtitles);

maciel310
07-31-2003, 01:42 AM
Ok, thank you, works fine now. Now hopefully this will be the last time I need to post here for help, thanks for all your help and patience.

I'm updating the page I gave above with this new script.