[Pdx-pm] Extra level in Hash of Array

Daniel Herrington herda05 at gmail.com
Wed Nov 18 06:50:36 PST 2009


All,

I have two code snippets that should do the same thing, but do not 
produce the same data structure. I can't seem to figure out why.
Code A:
...
                if ($boxNameH{$boxName}) {
                    #If we already have a list created
                    my $refBoxName = $boxNameH{$boxName};
                    my @derefArray = @$refBoxName;
                    $derefArray[0]++;
                    push (@derefArray, $jobName);
                    $boxNameH{$boxName} = \@derefArray;
                    $caJIL{$jobName}{"$jilCommand"} = "$jilValue";
                } else {
                    #We're the first one
                    my @derefArray;
                    $derefArray[0] = 1;
                    push (@derefArray, $jobName);
                    $boxNameH{$boxName} = \@derefArray;
                    $caJIL{$jobName}{"$jilCommand"} = "$jilValue";
                }
...
Using Dumper, the data in %boxNameH is:
3108$VAR1 = {
          'CPO_TNC_WCONV0' => [
                                2,
                                'CPO_TNC_WCONVERSION_CHMOD',
                                'CPO_TNC_WCONVERSION_SETUP'
                              ],
          'CURRENTLINK_25' => [
                                1,
                                'CURRENT_LINK_25'
                              ],
...

Code B:
...
    my %newBoxNameH;
    foreach (@arBoxNames) {
        my $boxName = $_;
        my $newBoxName;
        my @jobNamesList;
        if ($ref_hlqMap->{$boxName}) {
            $newBoxName = $ref_hlqMap->{$boxName} ; 
        } else {
            $newBoxName = $boxName;
        }
        print __LINE__ . " $newBoxName\n";
        my $ref_arJobNamesB = $ref_boxNameH->{$boxName};
        my @arJobNamesB = $ref_arJobNamesB;
        foreach (@arJobNamesB) {
            my $jobName = $_;
            my $newJobName;
            if ($ref_hlqMap->{$jobName}) {
                $newJobName = $ref_hlqMap->{$jobName};
            } else {
                $newJobName = $jobName;
            }
            if ($newBoxNameH{$newBoxName}) {
                my $ref_arJobNames = $newBoxNameH{$newBoxName};
                my @arJobNames = @$ref_arJobNames;
                push (@arJobNames,$newJobName);
                $newBoxNameH{$newBoxName} = \@arJobNames;
            } else {
                my @arJobNames;
                push (@arJobNames,$newJobName);
                $newBoxNameH{$newBoxName} = \@arJobNames;
            }
        }
...
289$VAR1 = {
          'CURRENTLINK_25' => [
                                [
                                  1,
                                  'CURRENT_LINK_25'
                                ]
                              ],
          'CPO_TNC_WCONV0' => [
                                [
                                  2,
                                  'CPO_TNC_WCONVERSION_CHMOD',
                                  'CPO_TNC_WCONVERSION_SETUP'
                                ]
                              ]
        };
...

You can see in Code B's dump that the list is actually embedded another 
layer down as if Code B produces a Hash of Array of Array. I just can't 
seem to figure out why this is happening?

thanks,

-- 
Daniel B. Herrington
Director of Field Services
Robert Mark Technologies
dherrington at robertmarktechnologies.com
o: 651-769-2574
m: 503-358-8575


More information about the Pdx-pm-list mailing list