How does one compare single character strings in Perl? Right now, I'm tryin to use "eq":
print "Word: " . $_[0] . "\n";
print "N for noun, V for verb, and any other key if the word falls into neither category.\n";
$category = <STDIN>;
print "category is...." . $category . "\n";
if ($category eq "N")
{
print "N\n";
push (@nouns, $_[0]);
}
elsif($category eq "V")
{
print "V\n";
push (@verbs, $_[0]);
}
else
{
print "Else\n";
push(@wordsInBetween, $_[0]);
}
But it isn't working. Regardless of the input, the else block is always executed.
How are you accepting the value of $category
? If it is done like my $category = <STDIN>
, you will have to chomp the newline at the end by:
chomp( my $category = <STDIN> );
eq is correct. Presumably $category is neither "N" nor "V".
Maybe there's unexpected whitespace in $category?
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