Thanks Ramprasad - that works.
At 17:29 20/05/2004 +0530, 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 ....................... }
> Surely I can avoid the "foreach" and inspect $field1 in the while loop for > uniqueness before pushing it to an array. > > Cheers, > Mark >
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>