First let's let the other list member in on the code:

use DBI;
use strict;
my $dbname = "test";
my $host = "localhost";
my $dbuser = '';
my $dbpw = '';
my $mscs = "dbi:mysql:dbname=$dbname;host=$host;";
my $dbh = DBI->connect($mscs, $dbuser, $dbpw) or die "Connect fails to
$dbname\nError = ", $DBI::errstr;
my $sql = "select * from method";
my $sth = $dbh->prepare($sql) or die "Prepare fails for
stmt:\n\t\t$sql\nError = ", $DBI::errstr;
my $rv;
unless ($sth->execute) {
 print"\n\tExecute fails for stmt:\n\t\t$sql\nError = ", $DBI::errstr;
 $sth->finish;
 $dbh->disconnect;
 die "\n\t\tClean up finished\n";
}
print "\t\t$rv\n\n" if $rv;
my %thehash;
my @row_ary;
my $row_ary;
my $key;

while (@row_ary  = $sth->fetchrow_array) {
 $key = $row_ary[0];
 $thehash{$key} = $row_ary[1];
}
$sth->finish;
$dbh->disconnect;
# all dbi stuff is done, show the hash
foreach $key (keys %thehash) {
 print"Key: $key   Value: $thehash{$key}\n";
}

> From the code, I think you're using the first field returned from the
> database as the key, and the second field as the value, but then
> discarding the third field. Am I understanding this correctly? I need to
Yes, it does discard the rest of the fetched information.
We can 'keep' it with another hash
my %otherhash;
then add
$otherhash{$key} = $row_ary[2];
to the while loop that fetches the db values.
This could get sloppy. A better approach may be to use a pseudohash
I posted the code hoping others will jump in with other options, but the
real issue is what do you need to do with the data? That will (possibly)
shed some light on the correct data structure to use, though you certainly
could
build a set of hashes with a common key one for each of the columns of the
table.
Let me see if I can work up an example of a pseudohash using the method
table.

> be able to recall all three parts of the information as needed. This is
> why I'm thinking this is a hash of arrays, with the hash key being the
> methodid, and the hash value being an array of methodid, method and
> sname.
>
> Thanks, again, for all your help. I'm certain my difficulty in
> understanding is due to my abilities, and not your explanations.
>
> -Kevin
>




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to