I'm working on a script that retrieves data from a database into a
hashref (using fetchall_hashref) and returns the hashref to the body
of the script before being used in a later subroutine. What seems to
be happening, though, is that the entire hashref is never being
returned. I get the primary hashref with all of the record
identifiers, but none of the fields exist. I *think* I've got the
syntax right, but I've been screwing with this for a full day now so
I'm hoping more experienced eyes can see what I'm missing. My
(relevant) code looks like this:
#
# In the main body of the script
#
my $eleref = get_elements();
# The element ID key exists, but with no fields as soon as it's
returned
print " AFTER RETURN: Iterating over keys in eleref->{'26276'}\n\n";
while ( my ($k, $v) = each %{$eleref->{'374039'} } ) {
print "key: $k, value: $v.\n";
}
#
# Subroutine to return all elements in a hashref
#
sub get_elements {
print "Retrieving elements for type checking...\n";
my $get_ele_sql = qq {
SELECT elem_id,
elem_typ_id,
root_elem_typ_id,
resoln_elem_typ_id
FROM t_elem_lkp
ORDER BY root_elem_typ_id
};
my $get_ele_sth = $nz->prepare ( $get_ele_sql )
or dienice ( "$get_ele_sql", $nz->err, $nz->errstr );
$get_ele_sth->execute();
my $eleref = $get_ele_sth->fetchall_hashref ( 'elem_id' );
# Values are printed for this element ID at this point
while ( my ($k, $v) = each %{$eleref->{'26276'} } ) {
print " key: $k, value: $v.\n";
}
$get_ele_sth->finish();
return $eleref;
}
Any help would be very much appreciated. Thank you.
Rob Wilkerson
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/