That is the array will need each key that has ch01.03...

If I understand correctly, you have pairs of UID and NAME. There will be several UIDs associated with each name. You want a list of all the unique names and for each name a list of all the UIDs associated with that name. The structure you need for this is a hash of arrays, and you can produce it at the same time you produce your ItemUID hash, as follows:

my %ItemUID = (); my %ItemName = (); #Get ItemUID and Item Name (ItemUID is unique to each Test.IData) { my $sql = "SELECT t.IData FROM Tests AS t JOIN Assignments AS a ON + a.A +ssignmentTestID=t.ID JOIN Users AS u ON u.ID=t.UserID WHERE u.Institu +tionID='004452' AND t.IData REGEXP 'ch01.03.MultipleChoice 049';"; my $sth = $dbh->prepare($sql); $sth->execute(); while ( my @row = $sth->fetchrow_array() ) { my $idata = $row[0]; while ( $idata =~ /<item([^>]+)/gi ) { my $elements = $1; my $src; my $uid; if ( $elements =~ /src=\"\w+\/([^"]+)/i ) { $src = $1 } if ( $elements =~ /uid=\"([^"]+)/i ) { $uid = $1 } if ( not exists $ItemUID{$uid} ) { $ItemUID{$uid} = $src; push(@{$ItemName{$src}}, $uid); } } } $sth->finish(); } # you can generate an array of the unique names if you like my @names = sort keys %ItemNames;

The hash $ItemName will have keys like 'ch02.03.MultipleChoice 029' and the values will be references to arrays of UIDs.

Hope this helps...


In reply to Re: Creating Array from Hash that pulls only Unique values while iterating over each Unique Value by ig
in thread Creating Array from Hash that pulls only Unique values while iterating over each Unique Value by kdmurphy001

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.