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
Latest posts by Rajesh Kumar (see all)
- Apache Lucene Query Example - April 8, 2024
- Google Cloud: Step by Step Tutorials for setting up Multi-cluster Ingress (MCI) - April 7, 2024
- What is Multi-cluster Ingress (MCI) - April 7, 2024