Just started to learn Perl and namely, learn program flow - main notable differences between evaluating strings and number and using the appropriate operators. Simple script, I have here is driving me crazy as it's a super simple, if else statement that should on "mike" being entered run and doesn't work. It outputs the else statement instead. Please help
#!C:\strawberry\perl\bin\perl.exe
use strict;
#use warnings;
#use diagnostics;
print("What is your name please?");
$userName = <STDIN>;
if($userName eq "mike"){
print("correct answer");
}
else{
print("Wrong answer");
}
Try adding a call to chomp after you get your value from STDIN:
$userName = <STDIN>;
chomp($userName);
Since the value read in from STDIN will have a newline character on the end. The chomp() built-in will remove a newline from the end of a string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With