rajeshkumar created the topic: perl validation on hash key is defined or not
Solutions Thanks Len for example program.
our %SERVERS = (
“rajesh1” => {type => ‘prod’, sha => ‘ram’},
“rajesh2” => {type => ‘prod’, sha => ‘sita’},
“rajesh3” => {type => ‘xyz’, named => [“raa”]},
“rajesh4” => {type => ‘xxx’, named => [“rajjaj”]},
);
while (my $mServer = each %SERVERS) {
if ($SERVERS{$mServer}{type} eq “prod” && !$SERVERS{$mServer}{named}) {
print “$mServer\n”;
}
}
Other sols
if ($SERVERS{$mServer}->{type} eq “prod” &&
! defined $SERVERS{$mServer}->{named} )
More Reference:
perldoc.perl.org/functions/exists.html
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn
- Discover the Heart of India with Mera Apna Bihar - December 20, 2024
- Experience the Pulse of Bangalore with Bangalore Orbit - December 20, 2024
- Discover the City of Lakes with Bhopal Orbit - December 20, 2024