Perl- Diagnostic hash print needed
Posted by: MajorGeek
Posted on: 2006-11-03 10:40:00
I'm having a lot of trouble getting past this point in a Perl script that takes user input search criteria and searches our publications and formats the output. I've inserted debug print statements in to discover the SQL statement is exactly what I want. When I replace the fetchrow_hashref and the call to the display_listing routine with:
while (my @row= $sth->fetchrow_array ())
{
print "$row[0] $row[1] $row[2] $row[3]<br/>n";
}
I get the correct but unformatted data.
I can't seem to get anything out to the original hash. I must have a fundamental misunderstanding about how hashes work. What would be a way to insert a diagnostic dump of the hash contents before I jump into the display_listing?
The code in part:
#@ CONSTRUCT_QUERY
#$col_list = "*";#
# #
# WHERE clause listing the conditions
$where = "WHERE
(`tblLitDtlYear`.`ID` = `tblLitMaster`.`ID`) AND
(`tblLitMaster`.`ID` = `tblLitDtlCatgy`.`ID`) AND
(`tblLitMaster`.`ID` = `tblLitDtlAuthor`.`ID`) AND "
. join (" AND ", @condition) if @condition;
$where = "" unless $where;
# complete query
$stmt = "SELECT DISTINCT
`tblLitMaster`.`Title`,
`tblLitMaster`.`ID`,
`tblLitDtlYear`.`Year`,
`tblLitDtlCatgy`.`Category`,
`tblLitMaster`.`RptPhysAddress`
FROM
`tblLitMaster`,
`tblLitDtlYear`,
`tblLitDtlCatgy`,
`tblLitDtlAuthor`
$where
ORDER BY Year LIMIT 100";
# print "condition array = ", @condition,"nn";
# print "placeholder array = ", @placeholder,"nn";
# print "nn";
# print "where statement = $wherenn";
# print "SQL statement = $stmtnn";
#@ CONSTRUCT_QUERY
#
#@ EXECUTE_QUERY
$sth = $dbh->prepare ($stmt);
$sth->execute (@placeholder);
$count = $sth->rows;
while (my $ref = $sth->fetchrow_hashref ())
{
printf $ref->{Title},$ref->{RptPhysAddress};
# display_listing ($ref);
}
$sth->finish ();
print ("Sorry, no qualifying listings were found.") if !$count;
#@ EXECUTE_QUERY
This signature line intentionally blank.