Zia*_*hoy 4 string perl comparison
如何比较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]);
}
Run Code Online (Sandbox Code Playgroud)
但它没有用.无论输入如何,始终执行else块.
Ala*_*avi 13
你怎么接受它的价值$category
?如果这样做my $category = <STDIN>
,你将不得不在最后通过以下方式来修改换行符:
chomp( my $category = <STDIN> );
Run Code Online (Sandbox Code Playgroud)