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
- Best AI tools for Software Engineers - November 4, 2024
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024