my $a = "x"; while ($a ne "y") { ... chop $a; } #### unless ($files[0]){ print "\nSorry, no xml file(s) in script folder\n\nScript Terminated...\n\n"; } else{ ... # a gazillion rows } #### unless( scalar @files ){ warn "no files"; exit; } ... #### parse_file($_) for @files; #### foreach my $i ( 0 .. $count ){
  • to be more explicit (since you want an array), do unless( ref($doc->{$sub1}) eq 'ARRAY' ){ #### foreach my $sub1 ( sort keys %{ $doc } ){ ... # $sub1 foreach my $sub2Hash ( @{ $doc->{$sub1} } ){ for my $sub2 ( sort keys %$sub2Hash ){ unless (ref($sub2Hash{$sub2})) { ... # $sub2 $worksheet->Cells($rowCount, $colCount)->{Value} = $sub2; $worksheet->Cells($rowCount, $colCount)->{Value} = $sub2Hash{$sub2}; next; } foreach my $sub3Hash( @{$sub2Hash{$sub2}} ){ for my $sub3 ( sort keys %$sub3Hash ){ #### sub __add_non_array { my ($worksheet, $rowCount, $colCount, $sub) = @_; $worksheet->Cells($rowCount, $colCount)->{Value} = $sub; $worksheet->Cells($rowCount, $colCount)->Borders() -> {Weight} = 2; $colCount++; $worksheet->Cells($rowCount, $colCount)->{Value} = $doc->{$sub}; $worksheet->Cells($rowCount, $colCount)->Borders() -> {Weight} = 2; $rowCount++; $colCount--; return ($rowCount, $colCount); } while( my ($sub1, $aoh1) = each %$doc ){ unless (ref($aoh1) eq 'ARRAY') { ($rowCount,$colCount) = __add_non_array($worksheet, $rowCount, $colCount, $sub1); next; } foreach my $sub2Hash ( @$aoh1 ){ while( my ($sub2, $aoh2) = each %$sub2Hash ){ unless (ref($aoh2) eq 'ARRAY') { ($rowCount,$colCount) = __add_non_array($worksheet, $rowCount, $colCount, $sub2); next; } foreach my $sub3Hash ( @$aoh2 ){ while( my ($sub3, $aoh3) = each %$sub3Hash ){ unless (ref($aoh3) eq 'ARRAY') { ($rowCount,$colCount) = __add_non_array($worksheet, $rowCount, $colCount, $sub3); next; } foreach my $sub4Hash ( @$aoh3 ){ print "Collecting general information...\n"; while( my ($sub4, $aoh4) = each %$sub4Hash ){ unless (ref($aoh4) eq 'ARRAY') { ($rowCount,$colCount) = __add_non_array($worksheet, $rowCount, $colCount, $sub4); next; } print "Collecting $sub4 ...\n"; $subDataRow = scalar(@$aoh4) + ($rowCount + 1); my $worksheet = $workbook->Worksheets->Add({After=>$workbook->Worksheets($workbook->Worksheets->{Count})}); $worksheet -> {Name} = $sub4; $worksheet -> Range("A1") -> Font -> {Size}= 14; $worksheet -> Range("A1") -> Font -> {ColorIndex}= 2; $worksheet -> Range("A1") -> {Value} = "$sub4"; $worksheet -> Range("A1:E1") -> Merge; $worksheet -> Range("A1:E1") -> Interior -> {ColorIndex} = 25; $worksheet -> Range("A1:E1") -> Borders() -> {Weight} = 3; my $subDataCol = 1; foreach my $sub5Hash ( @$aoh4 ){ my $temp = ""; while( my ($sub5, $aoh5) = each %$sub5Hash ){ my $curID = $sub5Hash{enclosureNumber} || $sub5Hash{number} || 0;; my $nextup = ""; if(ref($aoh5) eq 'ARRAY'){ ################# # SUBINFORMATIE # ################# $sub 4 is rank $sub5 is attribuut van rank $sub6 is element binnen rank eg arrayref foreach my $sub6Hash ( @$aoh5 ){ # Nieuwe ArayRef, ExtentbyVol,StorageDeviceFRY (nieuwe titels maken if($nextup ne $sub5){ $new = 1; $subDataRow++; $subHeaderRow = $subDataRow; $subDataCol=1 ; $nextup = $sub5; } else {$new = 0;} $subDataRow++; while( my ($sub6, $val6) = each %$sub6Hash ){ # subinfo title on new element if ($temp ne $curID){ $temp = $curID; $worksheet->Cells($subDataRow, $subDataCol)->{Value} = "$sub4 : $curID"; $worksheet->Cells($subDataRow, $subDataCol)->Interior->{ColorIndex} = 33; $worksheet->Cells($subDataRow, $subDataCol)->{Font}->{Bold} = 1; $worksheet ->Cells($subDataRow, $subDataCol)-> Borders() -> {Weight} = 1; $subDataRow+=2; $subHeaderRow = $subDataRow; $subDataRow++; } # Header if($new){ $worksheet->Cells($subHeaderRow, $subDataCol)->{Value} = $sub6; $worksheet->Cells($subHeaderRow, $subDataCol)->{Font}->{Bold} = 1; $worksheet ->Cells($subHeaderRow, $subDataCol)-> Borders() -> {Weight} = 2; $worksheet ->Cells($subHeaderRow, $subDataCol)-> Borders() -> {ColorIndex} = 25; } $worksheet->Cells($subDataRow, $subDataCol)->{Value} = $val6; $subDataCol++; } $subDataCol=1; } } else{ # aoh5 is not an array ################### # MAIN INFORMATION# ################### # Index, if any of those, will be placed in first column if ($sub5 eq "number" || $sub5 eq "id" || $sub5 eq "enclosureNumber"){ $worksheet->Cells($mainHeaders, 1)->{Value} = $sub5; $worksheet->Cells($mainHeaders, 1)->{Font} -> {ColorIndex} = 25; $worksheet->Cells($mainHeaders, 1)->{Interior} -> {ColorIndex} = 15; $worksheet->Cells($mainHeaders, 1)->Borders() -> {Weight} = 2; $worksheet->Cells($mainHeaders, 1)->{Font}->{Bold} = 1; $worksheet->Cells($rowCount, 1)->{Value} = $aoh5; $worksheet->Cells($rowCount, 1)->{Font}->{Bold} = 1; $worksheet->Cells($rowCount, 1)->Borders() -> {Weight} = 2; } else{ unless ($worksheet->Cells($mainHeaders, $colCount)->{Value}){ $worksheet->Cells($mainHeaders, $colCount)->{Value} = $sub5; } if ($sub5 eq "wwpn"){ $worksheet->Cells($rowCount, $colCount)->{NumberFormat} = "0"; $worksheet->Cells($rowCount, $colCount)->Borders() -> {Weight} = 2; } $worksheet->Cells($rowCount, $colCount)->Borders() -> {Weight} = 2; $worksheet->Cells($rowCount, $colCount)->{Value} = $aoh5; $worksheet->Cells($mainHeaders, $colCount)->Borders() -> {Weight} = 2; $worksheet->Cells($mainHeaders, $colCount)->{Font}->{Bold} = 1; $worksheet->Cells($mainHeaders, $colCount)->{Font} -> {ColorIndex} = 25; $worksheet->Cells($mainHeaders, $colCount)->{Interior} -> {ColorIndex} = 15; $colCount++; $LastRow = $worksheet->UsedRange->Find({What=>"*", SearchDirection=>xlPrevious, SearchOrder=>xlByRows})->{Row}; } } } $rowCount++; $subDataRow++; $colCount=2; $worksheet -> Range("A:X") -> {Columns} -> Autofit; } $subDataRow=$rowCount+2;; $colCount=2; $rowCount=4; #Seperate general information on first sheet. } $rowCount=4; $colCount+=3; } } $rowCount=4; $colCount+=3; } } $rowCount=4; $colCount+=3; } } #### foreach my $sub2 ( sort keys %$sub2Hash ){ my $aoh2 = $sub2Hash->{$sub2};