I was going to use a hash of arrays, but that will get messy real quick. So how would I use a while loop to connect to my database and populate each record of the hash? Here's my current code:

while (my $records = $query_handle->fetchrow_hashref) { my $new_name = $records->{'ap_name'}; my $location = $records->{'building'}; my $first_name = $records->{'primary_name'}; my $first_ip = $records->{'primary_ip'}; my $second_name = $records->{'secondary_name'}; my $second_ip = $records->{'secondary_ip'}; my $third_name = $records->{'tertiary_name'}; my $third_ip = $records->{'tertiary_ip'}; my $group = $records->{'bldg_short'}; my $five_channel = $records->{'five_channel'}; my $configured = $records->{'configured'}; my $mac_name = $records->{'mac_name'}; #Add each element as a hash to an Array of Hashes (AoH) my $new_hash = { new_name => $new_name, location => $location, first_name => $first_name, first_ip => $first_ip, second_name => $second_name, second_ip => $second_ip, third_name => $third_name, third_ip => $third_ip, group => $group, five_channel => $five_channel, configured => $configured, mac_name => $mac_name }; push (@aps, $new_hash); }

Can I step through the array 'records' and enter unique records using a loop with $i? I don't know where to place the $i to make it work.


In reply to Re^2: Hash throws out duplicate values by spickles
in thread Hash throws out duplicate values by spickles

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.