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
  1. #!D:\apache2triad\perl\bin\perl.exe
  2. use warnings; #enabling warnings, better safe then sorry ;)
  3. use strict; #using strict, more maintainable code ;)
  4. my $usr; #defining variable for user
  5. my $q1; #variable for 1st number
  6. my $q2; #variable for 2nd number
  7. my $a; #variable for answer
  8. my $typ; #variable for type or operation
  9. my $poi; #variable for points
  10. my $al; #variable for user's answer
  11. my $line; #define variable for each line read
  12. my $acku; #variable for user on line
  13. my $acks; #variable for score on line
  14. my $logreg; #variable for weather loging in or registering
  15. my $usreg; #variable for desired username
  16. "login or register?\n"; #loging in or registering prompt
  17. $logreg = ;
  18. ($logreg);
  19. if($logreg eq "login") { #if user chose login
  20. "Please enter your username.\n";
  21. $usr = ; #Ask which user it is
  22. ($usr);
  23. (MULT, "mult") or "Can't open, PANIC! $!\n"; #open the file or die
  24. while ($line = ) { #go through each line
  25.  ($acku, $acks) = (",", $line); #split each line into 2 variables
  26.  if ($acku eq $usr) { #if the user if the one the user chose
  27.  $poi = $acks; #set points
  28.  last; #break out of loops
  29.  }
  30. }
  31. $q1 = (100); #random numbers for the first and second numbers
  32. $q2 = (100);
  33. $q1 = $q1; #make numbers 1 and 2 integers
  34. $q2 = $q2;
  35. $a = $q1 * $q2; #define answer
  36. "You currently have " . $poi . " points.\n"; #print how many points user has
  37. "\n";
  38. "What is " . $q1 . " x " . $q2 . "?\n"; #asks question
  39. $al = ;
  40. ($al);
  41. if($al eq $a) { #if user got it right
  42. "\n";
  43. "Correct! Two points have been added to your account!\n";
  44. $poi = $poi + 2; #update points to 2 more then it was
  45. (MULT); #close file to open it again ;)
  46. (MULT, ">>mult") or "Can't open, PANIC! $!\n"; #open the file or die
  47. while ($line = ) { #go through each line
  48.  ($acku, $acks) = (",", $line); #split each line into 2 variables
  49.  if ($acku eq $usr) { #if user is the one we want
  50.   MULT $usr . "," . $poi; #update line
  51.   #exit
  52.  }
  53. }
  54. } else { #if user got it wrong
  55. "\n";
  56. "Sorry! Incorrect!\n"; #rub it in their face ;)
  57. #exit
  58. }
  59. }
  60. if($logreg eq "register") { #if the user is trying to register
  61. "Enter a username you want to be\n"; #ask desired username
  62. $usreg = ;
  63. ($usreg); #close file to open it again ;)
  64. (MULT, "mult") or "Can't open, PANIC! $!\n"; #open the file or die
  65. while ($line = ) { #go through each line
  66.  ($acku, $acks) = (",", $line); #split line into 2 variables
  67.  if ($acku eq $usreg) { #if the username is what the user entered the username is already taken, die!
  68. "sorry, username is taken! Please restart script and try again.\n";
  69. #exit
  70.  }
  71. }
  72. #goes here if username wan't taken
  73. (MULT); #close file to open again
  74. (MULT, ">>mult") or "Can't open, PANIC! $!\n"; #open the file or die
  75. MULT "\n" . $usreg . "," . "0"; #add user to file
  76. "You have been seccefuly registered!"; #congratulate the user!
  77. #exit
  78. }
  79. #if user entered something other then "login" or "register" tell them and exit
  80. if($logreg ne "login" and $logreg ne "register") {
  81. "please enter either login or register.\n";
  82. }

PermaLink to this entry https://pastebin.co.uk/7180

The following amendments have been posted:

  1. 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