Link to home
Start Free TrialLog in
Avatar of gauravflame
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}{$role}{$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 ?


ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial