perl - string comparison in foreach -
the below test check software information on list of ip addresses. program prints version of software running on ips expected.
now, test whether software running on ips identical? how do that?
sub test_check_software_info_on_all_the_ips { ($self) = @_; $self->{'machine_ip'} = $self->{'queryobj'}->get_machine_ip(); foreach $ip ( @{ $self->{'machine_ip'} } ) { $self->{'install_info'} = $self->{'queryobj'}->get_install_info($ip); info( 'software info of ' . $ip . ' ' . $self->{'install_info'} ); } }
sample output
20160907t141846 info software info of 1.1.1.1 r-2016-08-27-03 20160907t141846 info software info of 2.2.2.2 r-2016-08-27-03 20160907t141847 info software info of 3.3.3.3 r-2016-08-27-03 20160907t141847 info software info of 4.4.4.4 r-2016-08-27-03
this ask
sub check_matching_info { ($self) = @_; $ips = $self->{queryobj}->get_machine_ip; %info; $ip ( @$ips ) { $info = $self->{queryobj}->get_install_info($ip); push @{ $info{$info} }, $ip; } print keys %info == 1 ? "all ips have same install info" : "ips have different install info"; }
Comments
Post a Comment