> -----Original Message-----
> From: Scott Taylor [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, July 18, 2002 5:08 PM
> To: [EMAIL PROTECTED]
> Subject: populating hash from DBI
>
>
> Hello,
>
> I'm having a heck of a time populating a hash from an SQL statement.
>
> Here is what I have so far (which doesn't work of course)
>
> my $SQL = qq[SELECT triid, numlegs from tri_id];
>
> my $sth = $dbh->prepare($SQL);
> $sth->execute;
>
> no warnings 'uninitialized';
> my %numlegs;
>
> while ( %numlegs = $sth->fetchrow ){};
>
> That last line was the last straw, I tried every other way I
> could think
> of, and I can't find anything in perldocs about it either.
>
> Can anyone show me how to fix that last line to make it
> populate the hash,
> column[1]=>column[2].
Each pass through the loop overwrites %numlegs, so it will only
contain one entry, corresponding to the last row.
You can do something like this:
while (my $a = $sth->fetchrow_arrayref) {
$numlegs{$a->[0]} = $numlegs{$a->[1]};
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]