HoH

Work fine with below ::

%HoH = (
        flintstones => {
                lead      => "fred",
                pal       => "barney",

                Mount1 => {
                             'A'  => '1',
                          }
         },


 );

 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 "} ";
        }else{
           print "$role=$HoH{$family}{$role} ";
        }

     }
     print "}\n";
 }

=================================
Now add "main" to %HoH to get more information::
%HoH = (
        flintstones => {
                lead      => "fred",
                pal       => "barney",

                Mount1 => {
                             'A'  => '1',
                          }


              main  => "Common",                    # added to %HoH

        },


 );

 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 "} ";
        }else{
           print "$role=$HoH{$family}{$role} ";
        }

     }
     print "}\n";
 }

But I am gettting error that :
"Syntax error at Main" .  
Question ::
How to fix foreach for this error ?








gauravflameAsked:
Who is Participating?
 
mjcoyneCommented:
to fix the syntax error, add a comma as below:

%HoH = (
    flintstones => {
        lead   => "fred",
        pal    => "barney",
        Mount1 => {
            'A'   => '1',
            },                           # add a comma here
        main  => "Common",  # added to %HoH
                   }
 );
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.