Ramprasad A Padmanabhan wrote: > > Wow, > unique items is surely an FAQ. > But here you dont need to filter the array, just see the answer inline > > On Thu, 2004-05-20 at 17:07, Mark Martin wrote: > > Hi, > > I'm moving database data from table to table and want to make sure I'm > > getting only unique records. > > > > Only want unique $field1 and was looking at the cookbook code, but for that > > I have to populate a hash and then re-inspect through before inserting > > uniques, something like : > > > > %ucnt = (); > > while (my @row = $sth->fetchrow) { > > > > $field1 = $row[0]; > > push(@list,$field1 ); > > $ucnt{$_}++; > > $field2 = $row[3]; > > } > > > > Change that to > %ucnt = (); > while (my @row = $sth->fetchrow) { > $field1 = $row[0]; > push(@list,$field1 ); > $field2 = $row[3]; > > next if($ucnt{$_}++); > POPULATE TABLE ....................... > }
...except that $_ isn't being assigned here. Something like this should be closer. HTH, Rob my $sth; my @list; my %count; while (my @row = $sth->fetchrow) { my $field1 = $row[0]; push(@list, $field1); my $field2 = $row[3]; unless ($count{$field1}++) { # POPULATE TABLE ....................... } } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>