【发布时间】:2014-10-21 06:52:54
【问题描述】:
对于 Perl 来说仍然非常新,如果这看起来很基本,请原谅我,但我已经在谷歌上搜索了很长一段时间。我有 2 个变量;每行都有多个 IP 地址。
变量$a
111.11.11.11
333.33.33.33
111.11.11.11
变量$b
222.22.22.22
111.11.11.11
222.22.22.22
我想做一个“如果这 2 个变量中的任何 ips 匹配,则继续”的 if 语句。例如:
print "What is the website that is offline or displaying an error?";
my $host = readline(*STDIN);
chomp ($host);
# perform the ping
if( $p->ping($host,$timeout) )
{
#Host replied! Time to check which IP it is resolving to.
my $hostips = Net::DNS::Nslookup->get_ips("$host");
$hostips =~ s/$host.//g;;
}
#We have a list of IPs, now we need to make sure that IP resolves to this server.
#This is where the 2nd if statement begins (making sure one of the ips in both arrays match).
else
{
print "".$host." is not pinging at this time. There is a problem with DNS\n";
}
$p->close();
我必须记住,这是一个 if 语句中的一个 if 语句(它将继续到更多的 if 语句中)
【问题讨论】:
标签: arrays perl variables match