MAXcom
asked on
ozo, pcuser 321.. HELP!?
Hi,
Here is a script that is supposed to take your email,password and score and then write that your line of a txt file. Then it is supposed to check the high scores file and if your score is higher than any of them, put yours in and bump the rest down by one. Then it it supposed to write your alias and score to a lastpost file so i know who the last person that posted was. Note: on the lastpost file, i dont want to append, just overwrite the existing.
After all that is done, i just want the user to be redirected to my main page.
It seemed to be going ok but i am having A LOT of trouble trying to get the bugs out. Yes i know the script is extremely messy but im just starting. (if thats an excuse). Would you please look at the script and tell me why it wont execute?
#!/usr/bin/perl
use CGI;
$query= CGI->new();
$email = $query->param('email');
$passwd = $query->param('password');
$score = $query->param('score');
$email=lc($email);
$passwd=lc($passwd);
if ($email eq ""){&leave;}
if ($passwd eq ""){&leave;}
sub leave{
print "Content-type: text/html\n\n";
print "Something is wrong. Please hit your back button and try again.\n";
exit;
}
&checkpass;
sub checkpass{
$file = "reg_".substr($email,0,1). ".txt";
open (FILE,"$file");
@people = <FILE>;
foreach $line (@people){
chomp($line);
($mail,$pass,$score,$alias ) = split /\|/, $line;
if ($email eq $mail) {
if ($passwd eq $pass) {&decryptscore;} else {&nomail;}
}
else {&nomail;}
}
close(FILE);
}
sub nomail{
print "Content-type: text/html\n\n";
print "Invalid login. Are you sure you are registered? Click <a href=\/directory/register\ .htm>HERE< \/a> to register or your back button to try again.\n";
}
sub decryptscore{
$pattern="(2x)(9-E)(30X)(9 -A)(10X)(9 -D)(20X)(9 -H)(9X)(9- J)(16X)(9- B)(6X)(9-G )(9-F)(36X )(9-C)(84X *)(9-I)(X) ";
$pattern=~s/\((\d*)X\*\)/z $1/gi;
$pattern=~s/\((\d*)X\)/x$1 /gi;
$pattern=~s/\(9-(\w)\)/$1/ g;
@N = $pattern=~/([A-Z])/g;
($p84=$pattern) =~ tr/zxA-Z/axx/;
($px=$pattern) =~ tr/zxA-Z/xax/;
($pn=$pattern) =~ tr/zxA-Z/xxa/;
$px =~ s/a9/x9/;
$x84=unpack $p84,$score;
$x = substr((join'',unpack $px,$score),0,length $x84);
$x=~s/(\d)/9-$1/eg;
if ($x eq $x84){
@n{@N} = unpack $pn,$score;
$dscore=(9x@N)-join'',@n{' A'..'J'};
&writeit;
&checkhigh;
&writelast;
} else {&cheater;}
}
sub cheater{
print "Content-type: text/html\n\n";
print "The encrypted score is invalid.\n";
exit;
}
sub writeit{
$file = "reg_".substr($email,0,1). ".txt";
open (FILE,"$file");
open (TMPFL,">>temp.tmp");
@ids = <FILE>;
foreach $line (@ids){
chomp($line);
($mail,$pass,$score,$alias ) = split /\|/, $line;
if ($mail ne $email) {print TMPFL "$line\n";} else {
$theline = $email."|".$passwd."|".$ds core."|".$ alias;
print TMPFL "$theline\n";}
}
close(TMPFL);
close(FILE);
unlink($file);
rename "temp.tmp",$file || die("Unable to rename.");
}
sub checkhigh{
$file = "high.txt";
open (FILE,"$file");
@people = <FILE>;
foreach $line (@people){
chomp($line);
($no,$alia,$scor) = split /\|/, $line;
if ($score > $scor) {$l = 1}}
close(FILE);
if ($l == 1){&writehigh;}
}
sub writehigh{
$nom = 0;
$file = "high.txt";
open (FILE,"$file");
open (TMPFL,">>high.tmp");
@ids = <FILE>;
foreach $line (@ids){
chomp($line);
$nom++;
($no,$ali,$sco) = split /\|/, $line;
$line = $nom."|".$ali."|".$sco;
if ($sco > $scor) {print TMPFL "$line\n";} else
{
$theline = $nom."|".$alias."|".$dscor e;
print TMPFL "$theline\n";
}
}
close(TMPFL);
close(FILE);
unlink($file);
rename "high.tmp",$file || die("Unable to rename.");
}
sub writelast{
$file = "lastpost.txt";
open (FILE,">$file");
$theline = $alias."|".$dscore;
print FILE "$theline\n";
close(FILE);
print "Location: http:\/\/www\.mydomain\.com\/directory\/index1\.shtml\n\n";
exit;
}
Here is a script that is supposed to take your email,password and score and then write that your line of a txt file. Then it is supposed to check the high scores file and if your score is higher than any of them, put yours in and bump the rest down by one. Then it it supposed to write your alias and score to a lastpost file so i know who the last person that posted was. Note: on the lastpost file, i dont want to append, just overwrite the existing.
After all that is done, i just want the user to be redirected to my main page.
It seemed to be going ok but i am having A LOT of trouble trying to get the bugs out. Yes i know the script is extremely messy but im just starting. (if thats an excuse). Would you please look at the script and tell me why it wont execute?
#!/usr/bin/perl
use CGI;
$query= CGI->new();
$email = $query->param('email');
$passwd = $query->param('password');
$score = $query->param('score');
$email=lc($email);
$passwd=lc($passwd);
if ($email eq ""){&leave;}
if ($passwd eq ""){&leave;}
sub leave{
print "Content-type: text/html\n\n";
print "Something is wrong. Please hit your back button and try again.\n";
exit;
}
&checkpass;
sub checkpass{
$file = "reg_".substr($email,0,1).
open (FILE,"$file");
@people = <FILE>;
foreach $line (@people){
chomp($line);
($mail,$pass,$score,$alias
if ($email eq $mail) {
if ($passwd eq $pass) {&decryptscore;} else {&nomail;}
}
else {&nomail;}
}
close(FILE);
}
sub nomail{
print "Content-type: text/html\n\n";
print "Invalid login. Are you sure you are registered? Click <a href=\/directory/register\
}
sub decryptscore{
$pattern="(2x)(9-E)(30X)(9
$pattern=~s/\((\d*)X\*\)/z
$pattern=~s/\((\d*)X\)/x$1
$pattern=~s/\(9-(\w)\)/$1/
@N = $pattern=~/([A-Z])/g;
($p84=$pattern) =~ tr/zxA-Z/axx/;
($px=$pattern) =~ tr/zxA-Z/xax/;
($pn=$pattern) =~ tr/zxA-Z/xxa/;
$px =~ s/a9/x9/;
$x84=unpack $p84,$score;
$x = substr((join'',unpack $px,$score),0,length $x84);
$x=~s/(\d)/9-$1/eg;
if ($x eq $x84){
@n{@N} = unpack $pn,$score;
$dscore=(9x@N)-join'',@n{'
&writeit;
&checkhigh;
&writelast;
} else {&cheater;}
}
sub cheater{
print "Content-type: text/html\n\n";
print "The encrypted score is invalid.\n";
exit;
}
sub writeit{
$file = "reg_".substr($email,0,1).
open (FILE,"$file");
open (TMPFL,">>temp.tmp");
@ids = <FILE>;
foreach $line (@ids){
chomp($line);
($mail,$pass,$score,$alias
if ($mail ne $email) {print TMPFL "$line\n";} else {
$theline = $email."|".$passwd."|".$ds
print TMPFL "$theline\n";}
}
close(TMPFL);
close(FILE);
unlink($file);
rename "temp.tmp",$file || die("Unable to rename.");
}
sub checkhigh{
$file = "high.txt";
open (FILE,"$file");
@people = <FILE>;
foreach $line (@people){
chomp($line);
($no,$alia,$scor) = split /\|/, $line;
if ($score > $scor) {$l = 1}}
close(FILE);
if ($l == 1){&writehigh;}
}
sub writehigh{
$nom = 0;
$file = "high.txt";
open (FILE,"$file");
open (TMPFL,">>high.tmp");
@ids = <FILE>;
foreach $line (@ids){
chomp($line);
$nom++;
($no,$ali,$sco) = split /\|/, $line;
$line = $nom."|".$ali."|".$sco;
if ($sco > $scor) {print TMPFL "$line\n";} else
{
$theline = $nom."|".$alias."|".$dscor
print TMPFL "$theline\n";
}
}
close(TMPFL);
close(FILE);
unlink($file);
rename "high.tmp",$file || die("Unable to rename.");
}
sub writelast{
$file = "lastpost.txt";
open (FILE,">$file");
$theline = $alias."|".$dscore;
print FILE "$theline\n";
close(FILE);
print "Location: http:\/\/www\.mydomain\.com\/directory\/index1\.shtml\n\n";
exit;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Adjusted points to 9
ASKER
Hi,
Thanks a lot. That worked. I didnt realise that overwriting it would cause a problem.
The High Scores are kept as:
rank(1-10)|Alias|Score
this is the only part that apparently didnt work. How do you sort an array?
Thanks a lot. That worked. I didnt realise that overwriting it would cause a problem.
The High Scores are kept as:
rank(1-10)|Alias|Score
this is the only part that apparently didnt work. How do you sort an array?
ASKER
nevermind, i got it working the way i had it.
thanks
thanks
Thanks for the points.
This is what I was talking about
(lots simpler than yours):-
# All scores in scores high.txt are stored like the quoted text below.
# Here is the new score that we want to test
#
$NewScoreAndAlias = "0000123333|PC_User321";
($NewScore, $NotUsed) = split (/|/, $NewScoreAndAlias);
# Read the high scores and add the new one to the list
open (SCORES, "+< high.txt");
@Scores = <SCORES>;
push @Scores, "$NewScoreAndAlias\n";
# Sort the scores and dump the worst one
@Scores = sort @Scores;
shift @Scores; # Push out the lowest score
# Don't know why the program wants these
close (SCORES);
open (SCORES, "> high.txt");
# Write back to file
print (SCORES @Scores);
close (SCORES);
This is what I was talking about
(lots simpler than yours):-
# All scores in scores high.txt are stored like the quoted text below.
# Here is the new score that we want to test
#
$NewScoreAndAlias = "0000123333|PC_User321";
($NewScore, $NotUsed) = split (/|/, $NewScoreAndAlias);
# Read the high scores and add the new one to the list
open (SCORES, "+< high.txt");
@Scores = <SCORES>;
push @Scores, "$NewScoreAndAlias\n";
# Sort the scores and dump the worst one
@Scores = sort @Scores;
shift @Scores; # Push out the lowest score
# Don't know why the program wants these
close (SCORES);
open (SCORES, "> high.txt");
# Write back to file
print (SCORES @Scores);
close (SCORES);
The ranking (1st, 2nd,..) need not be in the file because the line number in the file gives that info.
ASKER
amazing.
ASKER
32905634009932754887810741