Staying in an else
I wrote this code in Perl, but it does not work correctly. I think it stays at the final else, and while does not work.
By the way, the goal of this program is to:
Receive users name and check it.
If the user name was equal to "javad" , print hello.
Else test user for a key.
#!/usr/bin/perl
#1.Greeting
@keys = qw(test 1234 root);
$WhileTest = "True";
$i = 0;
print "What is your name?\n";
$name = ;
chomp($name);
if ($name eq "javad") {
print "Hello !\n";
}
#2.Start for key testing
#instruction :? recieve the guess and compare it with keys list
else {
print "Welcome $name\n";
print "What is the key?\n";
$UserGuess = ;
chomp($UserGuess);
while ($WhileTest eq "True") {
if ($UserGuess eq $key[$i]) {
print "Successed !\n";
$WhileTest = "False";
}
elsif ($i < 2) {
$i = $i + 1;
}
else {
print "Try Again :\n";
$UserGuess = ;
chomp($UserGuess);
$i = 0;
}
}
}