my $req = ; my $sth = $dbh->prepare( qq{ SELECT tr_code,j_trs from t_ghos } ) or die "Can't prepare statement: $DBI::errstr"; $sth->execute or die "Can't execute statement: $DBI::errstr"; my $rows = $sth->fetchall_arrayref(); my $num_rows = @$rows; if($num_rows > 0) { process($sth,$req); } sub process { my $sth = shift; my $type = shift; while (my $row = $sth->fetchrow_hashref) { next unless defined($row); } }