Perl - 简单if语句不起作用

Bre*_*ett 2 perl stdin

我正在尝试编写一个循环来确定用户输入是否与字符串$ rev匹配.无论我为$ seq键入什么,它都会返回它不匹配,即使它实际上是.我究竟做错了什么?谢谢你的帮助.

$seq = <>;
$rev = "string";
if ($seq eq $rev){
    printf("The two strings match.\n");
}
else {
    printf("The two strings do NOT match.\n");
}
Run Code Online (Sandbox Code Playgroud)

too*_*lic 8

您需要终日啃食你输入删除换行符:

$seq = <>;
chomp $seq;
$rev = "string";
if ($seq eq $rev){
    print "The two strings match.\n";
}
else {
    print "The two strings do NOT match.\n";
}
Run Code Online (Sandbox Code Playgroud)

此外,使用print而不是printf因为您没有指定格式.