Need some help with perl (kinda similar to PHP)
``` use strict; use warnings; print" ---------------------------------------- Index ---------------------------------------- 1: Docknumbers 2: Exit ----------------------------------------\n Choose Program... "; my $y=0; while ($y==0){ #to prevent the program from closing after 1 run my $x=<STDIN>;chomp($x); #variable to start program (1) or exit (2) if($x==1){ my $w=1; #variable for program loop print"\n\tDock\tPIN\n----------------------------------------\n"; while($w==1){ #to keep program in loop my @dock = ( #array of dock numbers and corresponding pin numbers [54,55,56,57,58,70,71,72,73,74,76,77,78,"\nChoose next program..."], [61,49,18,97,18,85,76,51,16,54,89,58,46] ); my @results; my $z=int(rand(13)); print"\t$dock[0][$z]\t";my $pininput=<STDIN>;chomp($pininput); #a random dock number is displayed, user has to enter correct pin if($pininput eq ""){print"vul aub wel wat in\n";} #check if pin input is empty elsif($pininput eq "exit"){$w=2, print @results."\n", print"\n".$dock[0][14];} #check if user wants to exit, it should print the incorrect answers elsif($pininput==$dock[1][$z]){print"Correct!\n";} #check if pin is correct else{push(@results, $dock[0][$z]), #if pin is false, add docknumber to array with wrong answers print"False! the right pin for dock $dock[0][$z] is $dock[1][$z]\n";} #display correct answer } if($x==2){ #to exit print"\nbye\n\n"; exit; } if($x>2){print"Invalid choise, choose again\n";} }
Let me explain the program: It's a practice case: In a warehouse, there are 13 different docks (to load trucks) All those docks have a pin number to open the door. The intention of the program is to create a little memory training game for new employers at the warehouse to remember the correct pins (as only truck loaders should be able to open the doors). The explanation of the functions are given in the code. The main part of the program just works fine, but I tried to add a result list when the user exits the program (enters exit in pininput field) Every time you make a mistake in the program, it should put (push) the docknumber of the incorrect answer in an array. upon exiting it should print the result array so the user can see which of the docks he didn't remember, and then sort this list by the amount of identical docknumbers in the array. can't get the last part to work. every time I exit the program it prints 0 1 anyone knows the error here?
Are you declaring your results variable every time the loop cycles?
It generates a random number between 0 and 12 (13 in the code is incorrect, should be 12) and puts that in the variable $z The corresponding pin number is in the @dock array, second row So if I print let's say $dock[1][$z] while the randomly generated number is 3, $dock[1][3] will return 97 (3 = door 57) It does not print that number as the user has to enter it, then the program checks if the given number is the same as 97. If so, it'll print correct! if it's wrong, it'll print a message and the right answer. In that same line I want it to put the dock number $dock[0][$z] in the result array. that's the only thing I can't get to work. It prints 0 1 every time I exit the program, see screen.
@e.mccormick
cx he left chu he nu want 2 help chu ;p
Nah. Just missed a notification. Probably on a bad orange war day.
you need some help with @perl ? :P
Join our real-time social learning platform and learn together with your friends!