?
Solved

Hash

Posted on 2007-07-24
1
Medium Priority
?
213 Views
Last Modified: 2010-03-05
%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 ?


0
Comment
Question by:gauravflame
1 Comment
 
LVL 85

Accepted Solution

by:
ozo earned 1000 total points
ID: 19561787
foreach $family ( keys %HoH ) {

     print "$family: { ";
     if( ref $HoH{$family} eq "HASH" ){
       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} ";
        }
     }
   }else{
         print $HoH{$family};
   }


      print "}\n";
   }
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question