$SQLBuy = $dbh_metro->prepare(<<"EndOfSQL"); SELECT * FROM BuyersSellers WHERE FileNumber = ? EndOfSQL $rv = $SQLBuy->execute($filenumber); while (my $hash_ref = $SQLBuy->fetchrow_hashref) { push @BuySellHashref, { %{$hash_ref} }; } undef $SQLBuy; $SQLPEOPLE = $dbh_metro->prepare(<<"EndOfSQL"); SELECT * FROM People WHERE PersonID = ? EndOfSQL foreach (@BuySellHashref) { $rv = $SQLPEOPLE->execute($_->{PersonID}); while (my $hash_ref = $SQLPEOPLE->fetchrow_hashref) { $_->{PersonID} = { %{$hash_ref} }; } } undef $SQLPEOPLE; foreach $buysell (@BuySellHashref) { if ($buysell->{BuyerORSeller} =~ /BUYER/i) { print "
##
push @BuySellHashref, { %{$hash_ref} };
####
Currently, a new hash reference is returned for each row. This
will change in the future to return the same hash ref each time,
so don't rely on the current behaviour.