I'm trying to get my if statement to catch when a person enters an input that says quit or exit but it isn't. Here is my code
use strict;
use warnings;
my $g=0;
my $rn = int(rand(25));
until ($g == $rn) {
$g = <STDIN>;
if ($g == $rn) {
print "You got it";
} elsif (chomp($g) eq "quit" || chomp($g) eq "exit") {
print "it triggered";
} elsif ($g > $rn) {
print "incorrect its lower";
} elsif ($g <$rn) {
print "incorrect its higher";
} else {
print "end";
}
}
}
The
elsif (chomp($g) eq "quit" || chomp($g) eq "exit) {
line is not catching despite numerous attempts to catch the error. I've tried printing off what the program is seeing to no avail. What I get in response when I type in quit from the strict/warnings is that
argument "quit\n" isn't numeric in numeric eq (==) at ./program24.pl line 30, <STDIN> line 1.
argument "quit" isn't numeric in numeric gt (>) at ./program24.pl line 36, line 1.
I've looked at several of the other posts on this but nothing from them seems to be whats causing this. What am I doing wrong?