我正在试图找出一种通过分隔符分割字符串的方法:并将它们保存为两个字符串。我在第9行尝试了一些东西,但它没有用。显然我想在@ping_host中找到@clients的存在,如果不存在则发送警报。有什么建议吗?
@ping_host = ['1232','1212'];
@clients = ['1232:RARB','1212:CBN'];
client_monitor_state(@ping_host);
sub client_monitor_state(@ping_host){
my $token = $properties{token};
@clients = split(/,/, $token);
foreach $client (@clients){
($client_id,$client_name)=m/(\w+)\s*:(.+)/; # here the client_id should have the first part of match string
if(! grep($client_id,@ping_host)){
print "Client noted is $client_name \n";
# mail the client that is not reachable
my $subject_line = "The client $client_name is not reachable";
smtp_send(server_name => $client_name, subject_name => $subject_line);
}
}
}
答案 0 :(得分:2)
你应该use warnings;
,因为它可能暗示了解决方案。您隐式使用$_
代替$client
,而您需要使用=~
代替=
use warnings;
use strict;
my $client = 'this:that';
my ($client_id, $client_name) = $client =~ m/(\w+)\s*:(.+)/;
print "$client_id,$client_name\n";
__END__
this,that