Ok so this question has been bothering me for some time. I’m running a module that connects to a database and returns values from a query. I have a script calling the module and attempting to return the value from the subroutine of the module. But since code is better than words here’s what I have:
sub selectCustomerName ($code){
connectDB() or die "Failed in subroutine";
#Selects customer name from customer table where code is $code
my $selectName = "SELECT * FROM customers WHERE code = ?";
my $sth = $dbh->prepare($selectName);
$sth->execute($code);
my $hash = $sth->fetchrow_hashref;
$hash->{customer_name} = $name;
return $name;
$sth ->finish();
$dbh->disconnect();
}
That’s my module, here’s my script:
#!/usr/bin/perl
require Connect;
use warnings;
my $dbh = Connect::connectDB();
my $results = Connect::selectCustomerName('38d');
print $results;
From a lot of messing around and switching variables I’ve got it to print 0, and the hash reference but never the actual value of the hash. Any help would be great thanks!
There are some mistakes. Try this:
finish()&disconnect()after thereturn, they will never be invoked.