in reply to SQL Lookup/HASH

I cannot say if you should query your database for all possible results and store them in a hash or query them one at a time as you find them. Apart from anything else I've no idea how big this dataset may be. However you do either:

# prepare the sql once my $sth = $dbh->prepare(q/select column1 from mytable where column2 = +?/); # while(something) { # assuming only one column and one row are returned $sth->execute($my_key_into_table); my ($column1) = $sth->fetchrow; }

or

my $hashref = $dbh->selectall_hashref(q/select column1,key_column from + mytable/, 'key_column');

Replies are listed 'Best First'.
Re^2: SQL Lookup/HASH
by drodinthe559 (Monk) on Mar 19, 2010 at 16:13 UTC
    Thanks, the data set isn't large at all.