我在变量$vreponse
中有一个字符串,字符串是
int.force_snmp_version T_SIZE 3
我想要做的就是验证字符串中是否有数字3。如果验证成功则打印消息或打印失败消息
我尝试过这样的事情
my $vresponse = $ua->get("https://$user:$pass\@$ern_ip/get_param?p=init.force_snmp_version");
if ($vresponse->decoded_content =~ /\b3$/)
{
print "SUCESS\n";
}
else
{ print "not\n"; }
这不起作用,我是否需要更改$vresponse->decoded_content
?
答案 0 :(得分:1)
也许只是
if ( $vresponse =~ /3/ ) { ... }
只检查字符串中某处有3
个字符。
或者,更确切地说是
if ( $vresponse =~ /\b3$/ ) { ... }
检查 last 字符是否为3
并且它是单独的,即不是23
的结尾。
答案 1 :(得分:0)
my $vresponse = 'int.force_snmp_version T_SIZE 3';
my $char = '3';
my $result = index($vresponse , $char);
if ($result >=0)
{
#display found
}
else
{
#display not found
}