Sara wrote:
> Following is the code used in my CGI script.
> 
> my $query = $dbh -> prepare("SELECT * FROM invoices WHERE ID =
> '$ID'"); $query -> execute();
> while (my @row = $query -> fetchrow_array()){
> print "$row[1] - $row[2] - $row[3]<br>";
> }
> 
> What If I want to remove dupes from @row? like if $row[2] is similar
> in multiple records, only one entry should be showed, the duplicates
> should not appear in the print.  

Like Chris said, typically you want to use SELECT DISTINT or GROUP BY in
your query. The rule of thumb is to avoid sending unecessary data from the
server to the client.

But the general Perl construct I would use to filter dups is something like:

   my %found;
   while (...more data...) {
      $key = ...some expression...
      next if $found{$key}++;
      ...process the data for the first occurence...
   }


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to