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.

my $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 ++; }
I had something akin to this
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.



"No matter where you go, there you are." BB

In reply to Record creation in nested loops by Ninthwave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.