my $countref = $dbh->selectrow_hashref('SELECT COUNT(*) AS num FROM objects WHERE parent=?', undef, $ref->[0]);
if ($countref->{'num'} == 0) {
if ($i == $count) {
my $countref = $dbh->selectrow_hashref('SELECT COUNT(*) AS num FROM objects WHERE parent=?', undef, $ref->[0]);
if ($countref->{'num'} == 0) {
if ($i == $count) {