On May 20, Jeff 'japhy' Pinyan said: > my (%count, %unique); > > while (my @row = $sth->fetchrow) { > my $field = $row[0]; > if ($count{$field}++) { delete $unique{$field} } > else { $unique{$field} = [ @row ] }; # or 1, or whatever you want > } > >Here, every time a row is seen, its count is incremented. If the count >(before incrementing) was true (that is, not 0), then we delete it from >the unique hash. If the count was false (that is, 0), then we add it to >the unique hash. > >This way you don't have to traverse over the %count hash for those >elements whose value is 1, you have a hash of the elements in %count whose >count is 1 already, the %unique hash.
I'm afraid I may have solved a different problem than the one you asked, mainly because you didn't show us what you did WITH the hash you created. I thought you wanted to work with elements that only appeared once, but Ramprasad has code that makes it look like you want to make sure you don't do something to the same row twice. So his code is probably what you want. But, wait. Why not add a DISTINCT clause to your SQL? -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ CPAN ID: PINYAN [Need a programmer? If you like my work, let me know.] <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>