I am trying to do here is after processing data from the DB in this "for loop", display the information to the screen, but I am running into a problem with duplicated values, I just can’t figure it out how to prevent this, I am trying to explain the issue with code, I hope some of you can understand what I am trying to do, otherwise I can answer more questions to explain my problem here, thanks!

for (my $i = 0; $i < @$sqlinfo; $i++) { my $user = $sqlinfo->[$i]{user}; # @check_user previously initiated - check here against previously f +ound names to avoid showing duplicated to the screen next if "@check_user" =~ /(^|\s)$user(\s|$)/; my $number = sqlinfo->[$i]{number}; my $show = "<a href=\"call.pl?user=$user\">$user</a>"; my $first = sqlinfo->[$i]{first}; my $lastn = sqlinfo->[$i]{lastn}; my $tel = sqlinfo->[$i]{tel}; my $email = sqlinfo->[$i]{email}; # @number_check has been previously initiated before if ("@number_check" =~ /(^|\s)$number(\s|$)/ ) { # The $user values here are: Joe1 Mary1 Joe1 Mary1 from $user variab +le as an example, how to avoid showing duplicated values in $userfina +l # I am trying to show Joe1 and Mary1 I tried the code below but its +not working. #trying my %unique; if ($unique{$user}) { next; } $unique{$user} = 1; #end trying - if I use the above nothing shows. #here its still printing all the names ignoring unique names. print "<br>Print this to check if I only got unique user: *$user*<br> +"; # @userfinal has been previously initiated before $userfinal = "$userfinal<tr><td>$show</td><td>$lastn, $firs</td><td>$ +tel</td><td>$email</td></tr>"; } }


Thanks again!

In reply to Duplicated values in a For Loop 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.