如何比較Perl中的單個字符字符串?現在,我試着用「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]);
}
但它不工作。無論輸入如何,else塊都始終執行。
是,用戶在進入換行符。把它趕走。 –
2009-06-25 11:26:19