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

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,
TolgarAsked:
Who is Participating?
 
lwadwellCommented:
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
 
tdlewisCommented:
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
 
ozoCommented:
use Data::Dumper;
print Dumper \%report;
0
 
TolgarAuthor Commented:
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
 
TolgarAuthor Commented:
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
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.