Vasanth Vasanth - 3 months ago 12
Perl Question

fetchrow_hashref issue in perl

I am not able to retrieve the output properly using the below code. Please help me to sort it out.

I am getting output differently to run in MySQL and Perl.

As of now it is returning undef when I use Dumper. But I want it to display null.

$reactivate_sth = $dbh->prepare("
SELECT
a,
b
FROM
table
WHERE
c = ?
AND
d = ?
ORDER BY
date DESC
");
$reactivate_sth->execute($c, $d);
print $result = $reactivate_sth->fetchrow_hashref();


OUTPUT:

MySQL:

Empty set (0.00 sec)


Perl:

HASH(0x3068198)


Data::Dumper

VAR1 = undef

Answer

Finally I found the solution for this issue. I am not sure this one is a proper fix or not.

Please guide me if the fix is not professional.

if (!defined $result->{''}) {
   $result = '';
}