?
Solved

How to read all the elements of a multi-dimensional hash in Perl?

Posted on 2012-08-21
5
Medium Priority
?
395 Views
Last Modified: 2012-08-28
I have a multidimensional hash. How can I read all the elements of this hash?

Please see the link below to get an idea about the structure of the hash:

http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_27837106.html


Thanks,
0
Comment
Question by:Tolgar
5 Comments
 
LVL 10

Assisted Solution

by:tdlewis
tdlewis earned 300 total points
ID: 38318465
Try something like this:

map {
  my $file = $_;
  map {
    my $check_no = $_;
      map {
        my $result = $_;
        reportResult($file,$check_no,$result);
      } sort keys %{$report{$file}{$check_no}};
  } sort keys %{$report{$file}};
} sort keys %report;

Open in new window

0
 
LVL 85

Assisted Solution

by:ozo
ozo earned 300 total points
ID: 38318574
use Data::Dumper;
print Dumper \%report;
0
 
LVL 25

Accepted Solution

by:
lwadwell earned 1400 total points
ID: 38319043
Have a look at this:
use strict;
use Data::Dumper;

my %report;

## Load up some dummy data
my @files = qw{xyzfile1 abcfile2};
my @checks = (2,1,3);
for my $fileTobeChecked ( @files ) {
	for my $checkno ( @checks ) {
		$report{ $fileTobeChecked }{ $checkno }{check} = 'yes';
	}
}
## Dump the result
print Dumper \%report;

## Loop through results (unsorted)
for my $file ( keys %report ) {
	print "fileTobeChecked = $file\n";
	for my $check ( keys %{$report{$file}} ) {
		print "  Checkno = $check  result = $report{$file}{$check}{check}\n";
	}
}

## Loop through results (sorted)
for my $file ( sort keys %report ) {
	print "fileTobeChecked = $file\n";
	for my $check ( sort keys %{$report{$file}} ) {
		print "  Checkno = $check  result = $report{$file}{$check}{check}\n";
	}
}

Open in new window

0
 

Author Comment

by:Tolgar
ID: 38320943
Can you please take a look at this follow-up question?

http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_27838095.html

Thanks,
0
 

Author Comment

by:Tolgar
ID: 38321623
I have another follow-up question. Can you please take look at it?

http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_27838406.html

Thanks,
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

864 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