gauravflame
asked on
Hash
%HoH = (
flintstones => {
lead => "fred",
pal => "barney",
Mount1 => {
'A' => '1',
},
main => "Common",
},
mainoutside => "Commonoutside", # like to display this part of Hash
);
foreach $family ( keys %HoH ) {
print "$family: { ";
for $role( keys %{ $HoH{$family} } ) {
if( ref $HoH{$family}{$role} eq 'HASH' ){
print "$role: { ";
for $role1 ( keys %{ $HoH{$family}{$role} } ) {
print "$role1=$HoH{$family}{$rol e}{$role1} ";
}
print "} ";
}
elsif (ref $HoH{$family} eq 'SCALAR') # Added this code to catch that value
{
print "\n $family=$HoH{$family}\n";
}
else{
print "$role=$HoH{$family}{$role } ";
}
}
print "}\n";
}
========================== ========== ==========
output ::
mainoutside: { } # Wrong output
flintstones: { lead=fred Mount1: { A=1 } pal=barney main=Common }
Question :: How to read "" mainoutside => "Commonoutside", "" of hash ?
flintstones => {
lead => "fred",
pal => "barney",
Mount1 => {
'A' => '1',
},
main => "Common",
},
mainoutside => "Commonoutside", # like to display this part of Hash
);
foreach $family ( keys %HoH ) {
print "$family: { ";
for $role( keys %{ $HoH{$family} } ) {
if( ref $HoH{$family}{$role} eq 'HASH' ){
print "$role: { ";
for $role1 ( keys %{ $HoH{$family}{$role} } ) {
print "$role1=$HoH{$family}{$rol
}
print "} ";
}
elsif (ref $HoH{$family} eq 'SCALAR') # Added this code to catch that value
{
print "\n $family=$HoH{$family}\n";
}
else{
print "$role=$HoH{$family}{$role
}
}
print "}\n";
}
==========================
output ::
mainoutside: { } # Wrong output
flintstones: { lead=fred Mount1: { A=1 } pal=barney main=Common }
Question :: How to read "" mainoutside => "Commonoutside", "" of hash ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.