且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我不能从Perl中的标准输入中匹配我的字符串?

更新时间:2023-11-14 11:35:28

语句$name = <STDIN>;从标准输入中读取,并且包括终止换行符"\n".使用chomp函数删除该字符:

The statement $name = <STDIN>; reads from standard input and includes the terminating newline character "\n". Remove this character using the chomp function:

print "What is your name?\n";
$name = <STDIN>;
chomp($name);
if ($name eq "Jon") {
  print "We have met before!\n";
} else {
  print "We have not met before.\n";
}