in reply to An Array Without and Index
The use of selectall_hashref (or selectall_arrayref) relieves you of having to prepare, execute and fetch* everything yourself. All that's left is to use the results (in this case as an in-memory hashed lookup for all addresses in @addr). On top of that, calling finish isn't neccesary when you are fetching *all* the results, only when you want to abort fetching results partly through.my @results; my $hr_addresses = $dbh->selectall_hashref("SELECT addr, id FROM u2add +r", "addr"); if (!defined $hr_addresses) { die("Error executing query: " . $dbh->er +rstr); } foreach my $addr (@addr) { if (defined $hr_addresses->{$addr}) { push(@results, $hr_addresses->{$addr}) } else { print("Error, ID of address [$addr] not found\n"); } }
|
|---|