小编mas*_*ral的帖子

if语句不会在perl中捕获字符串

当一个人输入一个表示退出或退出的输入时,我试图让我的if语句捕获,但事实并非如此.这是我的代码

use strict;
use warnings;
my $g=0;
my $rn = int(rand(25));
until ($g == $rn) {
      $g = <STDIN>;
      if ($g == $rn) {
            print "You got it";
            } elsif (chomp($g) eq "quit" || chomp($g) eq "exit") {
            print "it triggered";
            } elsif ($g > $rn) { 
            print "incorrect its lower";
            } elsif ($g <$rn) {
            print "incorrect its higher";
            } else {
            print "end";
            }      
}
}
Run Code Online (Sandbox Code Playgroud)

elsif (chomp($g) eq "quit" || chomp($g) eq "exit) {
Run Code Online (Sandbox Code Playgroud)

尽管多次尝试捕捉错误,但是线路并没有捕获.我试过打印出程序看到的东西无济于事.当我输入严格/警告退出时,我得到的回应是

argument …
Run Code Online (Sandbox Code Playgroud)

perl string-comparison

3
推荐指数
1
解决办法
177
查看次数

标签 统计

perl ×1

string-comparison ×1