Assuming we have a table named t in the current database schema, here is it:
my $dbh = shift;
my $sth = $dbh->prepare("select * from t");
print "An error occurred: ".$sth->errstr()."\n";
print "@row\n" while(@row = $sth->fetchrow_array());
print "An error occurred: ".$sth->errstr()."\n" if $sth->err();
The subroutine expects to be called with a valid database handle as a parameter, that we extract and put in the local variable $dbh. Then we prepare a SQL statement, putting the result in another local variable, $sth. We try to execute the statement and, in case of success, we loop calling fetchrow_array() on the statement to get the next row and simply printing it.