我编写了一个返回IP地址列表的函数。
我从我的测试脚本dns.pl
调用该函数,并使用for
循环一次传递一个地址作为命令的输入。
我想将除了一个IP地址之外的所有地址作为输入(一次性全部)传递给脚本中的命令。
我想检查地址是否匹配= x.x.x.x.如果是,则跳过该地址并将其他地址作为输入传递给脚本中的以下命令。
# The IP address that are retuned by the function should be passed here as input all at once. Except one ip address
./dns.pl -t ipaddress1,ip address2,.... ipadress,n -f .5 -S C
# function call to get the list of ip addresses
$self->{'machine_ip'} = $self->{'queryObj'}->get_machine_ip( $self->{'vip_owner'} );
# Currently, I'm passing one ip address at a time using foreach
# But, I want to pass all but one ip address all at once to the below command as input.
foreach my $ip ( @{ $self->{'machine_ip'} } ) {
$self->{'exec_obj'}->execute(./dns.pl -t ipaddress1,ip address2,.... ipadress,n -f .5 -S C);
}
sub get_machine_ip {
my ( $self, $vip_owner ) = @_;
my @ip = ();
my $sql_query = $self->{queryObj}->execute("select machineIP from sripd_peer_Status where frontend=$vip_owner");
my $records = $self->{queryObj}->result();
foreach my $row ( @$records ) {
push @ip, $row->{machineIP};
}
return \@ip;
}
答案 0 :(得分:3)
使用grep从阵列中删除不需要的IP地址。
$self->{machine_ip} = $self->{queryObj}->get_machine_ip($self->{vip_owner});
my @ips_minus_value = grep {$_ ne 'IP_ADDRESS_TO_REMOVE'} @{$self->{machine_ip}};
$self->{exec_obj}->execute("./dns.pl -t " . join(',', @ips_minus_value) . " -f .5 -S C");