Posted by DJ Thu 7th Dec 2006 22:45 - Syntax is Perl - 142 views
Modification of posting from DJ Thu 7th Dec 2006 22:40
Download | New Post | Modify | Diff | Diff | Hide line numbers
Modification of posting from DJ Thu 7th Dec 2006 22:40
Download | New Post | Modify | Diff | Diff | Hide line numbers
-
#!D:\apache2triad\perl\bin\perl.exe
-
use warnings; #enabling warnings, better safe then sorry ;)
-
use strict; #using strict, more maintainable code ;)
-
my $usr; #defining variable for user
-
my $q1; #variable for 1st number
-
my $q2; #variable for 2nd number
-
my $a; #variable for answer
-
my $typ; #variable for type or operation
-
my $poi; #variable for points
-
my $al; #variable for user's answer
-
my $line; #define variable for each line read
-
my $acku; #variable for user on line
-
my $acks; #variable for score on line
-
my $logreg; #variable for weather loging in or registering
-
my $usreg; #variable for desired username
-
"login or register?\n"; #loging in or registering prompt
-
$logreg =
; -
($logreg);
-
if($logreg eq "login") { #if user chose login
-
"Please enter your username.\n";
-
$usr =
; #Ask which user it is -
($usr);
-
(MULT, "mult") or "Can't open, PANIC! $!\n"; #open the file or die
-
while ($line =
) { #go through each line -
($acku, $acks) = (",", $line); #split each line into 2 variables
-
if ($acku eq $usr) { #if the user if the one the user chose
-
$poi = $acks; #set points
-
last; #break out of loops
-
}
-
}
-
$q1 = (100); #random numbers for the first and second numbers
-
$q2 = (100);
-
$q1 = $q1; #make numbers 1 and 2 integers
-
$q2 = $q2;
-
$a = $q1 * $q2; #define answer
-
"You currently have " . $poi . " points.\n"; #print how many points user has
-
"\n";
-
"What is " . $q1 . " x " . $q2 . "?\n"; #asks question
-
$al =
; -
($al);
-
if($al eq $a) { #if user got it right
-
"\n";
-
"Correct! Two points have been added to your account!\n";
-
$poi = $poi + 2; #update points to 2 more then it was
-
(MULT); #close file to open it again ;)
-
(MULT, ">>mult") or "Can't open, PANIC! $!\n"; #open the file or die
-
while ($line =
) { #go through each line -
($acku, $acks) = (",", $line); #split each line into 2 variables
-
if ($acku eq $usr) { #if user is the one we want
-
MULT $usr . "," . $poi; #update line
-
#exit
-
}
-
}
-
} else { #if user got it wrong
-
"\n";
-
"Sorry! Incorrect!\n"; #rub it in their face ;)
-
#exit
-
}
-
}
-
if($logreg eq "register") { #if the user is trying to register
-
"Enter a username you want to be\n"; #ask desired username
-
$usreg =
; -
($usreg); #close file to open it again ;)
-
(MULT, "mult") or "Can't open, PANIC! $!\n"; #open the file or die
-
while ($line =
) { #go through each line -
($acku, $acks) = (",", $line); #split line into 2 variables
-
if ($acku eq $usreg) { #if the username is what the user entered the username is already taken, die!
-
"sorry, username is taken! Please restart script and try again.\n";
-
#exit
-
}
-
}
-
#goes here if username wan't taken
-
(MULT); #close file to open again
-
(MULT, ">>mult") or "Can't open, PANIC! $!\n"; #open the file or die
-
MULT "\n" . $usreg . "," . "0"; #add user to file
-
"You have been seccefuly registered!"; #congratulate the user!
-
#exit
-
}
-
#if user entered something other then "login" or "register" tell them and exit
-
if($logreg ne "login" and $logreg ne "register") {
-
"please enter either login or register.\n";
-
-
}
PermaLink to this entry https://pastebin.co.uk/7180
The following amendments have been posted:
-
DJ (Thu 7th Dec 2006 22:48)
Posted by DJ Thu 7th Dec 2006 22:45 - Syntax is Perl - 142 views
Modification of posting from DJ Thu 7th Dec 2006 22:40
Download | New Post | Modify | Diff | Diff | Hide line numbers
Modification of posting from DJ Thu 7th Dec 2006 22:40
Download | New Post | Modify | Diff | Diff | Hide line numbers