Hi Monks!

I am querying a database table and returning several values
and as you can see the individual names for the Groups could be different depending in what will be coming from the query result.
I am trying to group all the same groups into different arrays so I can use them later. How could I do that if I don't know how many different values I will get for the
Groups which it will be in $account_name; I don't know if I am making myself clear here but here is a sample code of a possible situation.

while (my $pointer = $sth->fetchrow_hashref) { $c++; $account_name = $pointer->{'account_name'}; $username = $pointer->{'username'}; print "$c - $account_name = $username; #if I print this here it could return something like: =code 1 - Group A = John 2 - Group A = Mary 3 - Group A = Joe 4 - Group A = Ann 5 - Group A = Carl 6 - Group A = Joen 1 - Group B = Maria 1 - Group C = Junior 2 - Group C = Eva 3 - Group C = Mario 4 - Group C = Raimund 5 - Group C = Gerald 6 - Group C = Jasmin 7 - Group C = Rose 8 - Group C = Suelly # I have to find a way to whatever comes from my db query to be # separated by the group so later I could use on my program: # could be something like: push @array1 = all Group A and usernames an +d so forth... =cut }


Let say all I've got for this test here was the 3 different Groups, I could at the end do this after using maybe "push":
#Do something with @array1.
#Do something with @array2.
#Do something with @array3.


Thanks for the help!

In reply to Unique Array from DB by Anonymous Monk

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.