• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 645
  • Last Modified:

Hoe to create multidimensional hash in Perl?

How can I create a multi-dimensional hash in Perl?

Here is my example:

I would like to hash with this structure:

report 
          fileTobechecked
                                     fileNo=$fileNo
                                     checkResult=$checkResult
                                     textcolor=$textcolor
                                     check=$check

Open in new window



So, report will be the hash. fileNo, checkResult,  textcolor and check are the keys and their values change in a for loop.

Let me show you the part of my code:

In here I need a fileNo for each fileTobeChecked. The following code works fine actually.
    
my %report;

foreach my $fileTobeChecked (@allFilesTobeChecked) {
        $fileNo++;
		$report{ $fileTobeChecked }{ 'fileNo' } = $fileNo;

Open in new window


In here I need the check for each file and for each checkno for this file:

        foreach my $check (@Checks) {
            $checkno++;
            #removing new line character
            $check =~ s/\n//g;
			$report{ $fileTobeChecked }{ $checkno } = $check;

Open in new window


                                   
And in here, I need CheckResult for each file of for each checkno. But this has a problem. Because $report{ $fileTobeChecked }{ $checkno } is no longer a hash. It becomes a string.

$report{ $fileTobeChecked }{ $checkno }{ 'checkResult'} = $CheckResult;   

Open in new window

                               

But, the way I create these hashes, it does not work. Because, for the last example code, $report{ $fileTobeChecked }{ $checkno } is not a hash. it becomes a string. Therefore, I get  this error:

Can't use string ("  WARNING: The file type does no") as a HASH ref while "strict refs"

Open in new window


I cannot think of a way to create this hash?

Can you please help me?
0
Tolgar
Asked:
Tolgar
  • 2
1 Solution
 
ozoCommented:
instead of
$report{ $fileTobeChecked }{ $checkno } = $check;
use
$report{ $fileTobeChecked }{ $checkno }{check} = $check;
0
 
Ess KayEntrapenuerCommented:
i thought this question was about Hoes :(
0
 
TolgarAuthor Commented:
My typo:

How to create multidimensional hash in Perl?
0
 
TolgarAuthor Commented:
@ozo: Can you please take look at this follow up question?

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

Thanks,
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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now