I have a subroutine that queries a DB loads and loads a hash with the results:
My question is how do I dereference it in my program into the hash %db_results?
Thanks,
Nick
If at first you don't succeed, don't try skydiving.
Code:
sub VistaQuery {
my $vendor;
my $ip;
my %_sub_db_results;
my $data_source = "dbi:Oracle:binvdp01";
my $dbh = DBI->connect($data_source, $orauser, $orapass)
or die "Can't connect to $data_source: $DBI::errstr";
my $sth = $dbh->prepare( q{select T1.SVALUE, T2.SVALUE from twtpropvalues T1, twtpropvalues T2 where
T1.PROPID=(select ID from twtproperties where WID='00000000000000000000000000000001')
and T2.PROPID=(select ID from twtproperties where
WID='72B1577C795AB24888F4462B18D8F42D') and T1.INSID=T2.INSID}
) or die "Can't prepare statement: $DBI::errstr";
my $rc = $sth->execute
or die "Can't execute statement: $DBI::errstr";
print "Query will return $sth->{NUM_OF_FIELDS} fields.\n\n";
print "Field names: @{ $sth->{NAME} }\n";
while (($ip, $vendor) = $sth->fetchrow_array) {
$sub_db_results{$ip} = $vendor;
}
#
# check for problems which may have terminated the fetch early
#
die $sth->errstr if $sth->err;
$dbh->disconnect;
[b] return \%sub_db_results;[/b]
}# End sub VistaQuery
My question is how do I dereference it in my program into the hash %db_results?
Code:
my %db_results = VistaQuery??
Thanks,
Nick
If at first you don't succeed, don't try skydiving.