Here is my code. How do I loop through @Data which would be the row returned from my DBI query and assign the hashkey and values to my anonymous hash record.
I had something akin to thismy $DataCount = 0; while ( @Data = $ExcelQuery->fetchrow_array ) { # Loop through row data and assign to an anonymous hash in an arr +ay $AssetRecord = {$ExcelColumns[0] => $Data[0], $ExcelColumns[1] => $Data[1], $ExcelColumns[2] => $Data[2], $ExcelColumns[3] => $Data[3], $ExcelColumns[4] => $Data[4], $ExcelColumns[5] => $Data[5], $ExcelColumns[6] => $Data[6], $ExcelColumns[7] => $Data[7], $ExcelColumns[8] => $Data[8], $ExcelColumns[9] => $Data[9], $ExcelColumns[10] => $Data[10], $ExcelColumns[11] => $Data[11], $ExcelColumns[12] => $Data[12], $ExcelColumns[13] => $Data[13], $ExcelColumns[14] => $Data[14], $ExcelColumns[15] => $Data[15], $ExcelColumns[16] => $Data[16], $ExcelColumns[17] => $Data[17], $ExcelColumns[18] => $Data[18], $ExcelColumns[19] => $Data[19], $ExcelColumns[20] => $Data[20], $ExcelColumns[21] => $Data[21], }; $AssetEntries[$DataCount] = $AssetRecord; $DataCount ++; }
my $RowCount = 0; while (<@Data>){ $AssetRecord = $ExcelColumns[$RowCount] => $Data[$RowCount]; $RowCount ++; }
This of course creates a new anonymous hash so when the row is finished only the last hash reference and value gets stored in the array.
I am missing something simple.
I probably should just create an object. But before going OO want to understand my references better.
In reply to Record creation in nested loops by Ninthwave
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |