加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl – 为什么单个字符的字符串相等测试不起作用?

发布时间:2020-12-15 23:28:10 所属栏目:大数据 来源:网络整理
导读:如何比较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";i
如何比较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 "Nn";
    push (@nouns,$_[0]);
}
elsif($category eq "V")
{
    print "Vn";
    push (@verbs,$_[0]);
}
else
{
    print "Elsen";
    push(@wordsInBetween,$_[0]);
}

但它没有用.无论输入如何,始终执行else块.

解决方法

你如何接受$category的价值?如果它像我的$category =< STDIN>那样完成,你必须在最后通过以下方式选择换行符:

chomp( my $category = <STDIN> );

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读