如果声明失败

Rot*_*oto -3 perl json

好吧,我有这行代码,我无法弄清楚,如果有人可以帮助我,这将是伟大的.我正在制作一个地理位置perl脚本作为我项目的一部分.

这是代码行

$isps = $info->{'isp'};

if ($isps = "Time Warner Cable")
 {

  print "Isp found, go to $website for more information\n";       
}

if ($isps = "Google") {

    print "Isp found, go to $website for more information\n";       
} else {

    print "No ISP located! No way of Contact via this terminal!";
}
Run Code Online (Sandbox Code Playgroud)

好吧基本上我正在尝试使if语句读取JSON代码并使其在列出特定名称时打印某些文本.我正在向文件添加更多的ISP,但现在只是这两个.

如果有人能用这行代码帮助我,因为我真的无法弄明白.

amo*_*mon 5

=是赋值运算符.您想要字符串比较运算符eq.

在这一行要指定字符串"Time Warner Cable"$isps变量.然后if-conditional看到字符串并将其解释为true.对于下一个条件相同.

if ($isps = "Time Warner Cable")
Run Code Online (Sandbox Code Playgroud)

相反,你想要:

my $isps = $info->{'isp'};

if ($isps eq "Time Warner Cable") {
    print "Isp found, go to $website for more information\n";       
}
elsif ($isps eq "Google") {
    print "Isp found, go to $website for more information\n";       
} else {
    print "No ISP located! No way of Contact via this terminal!\n";
}
Run Code Online (Sandbox Code Playgroud)

  • 可能值得注意 - "使用严格;``使用警告;`告诉你这个.`发现=有条件的,应该是==` (2认同)