June 20th, 2013, 04:08 PM
While loop with multiple conditions
I have this loop in my program, but no matter what I put in, it won't exit the loop. How would I fix it?
while ($answer ne 'y' && $answer ne 'n')
print "invalid response, Overwrite file(y/n)?";
$answer = <STDIN>;
June 20th, 2013, 04:31 PM
What values does $answer has if you try to print it out after the assignment?
June 20th, 2013, 04:35 PM
if I type n, it prints n. if I type y it prints y.
Originally Posted by MrFujin
June 20th, 2013, 04:37 PM
You need to chomp $answer to remove the line terminator.
June 20th, 2013, 04:44 PM
June 20th, 2013, 04:50 PM
Chomp $answer, otherwise it will never be equal to y or n, but to y or n with a carriage return.
Originally Posted by Fullmetal99012
EDIT: Oops, I did not see that Fishmonger answered the same thing before.
June 21st, 2013, 12:31 PM
How did I miss this. so simple. I am soo dumb.
Originally Posted by FishMonger