Perl DBIでselect

mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| items          |
| name           |
| news           |
| user           |
+----------------+
4 rows in set (0.00 sec)

mysql> select * from items;
+---------+---------+-------+
| item_id | name    | price |
+---------+---------+-------+
|       1 | U+1F363 |  NULL |
+---------+---------+-------+
1 row in set (0.00 sec)

#!/usr/bin/perl --

use CGI;
use DBI;

print "Content-type:text/html\n\n";
print "hello";
my $user = 'root';
my $passwd = '';
my $db = DBI->connect('DBI:mysql:test:localhost', $user, $passwd);
my $sth = $db->prepare("select * from items;");
$sth->execute();
while (my $ary_ref = $sth->fetchrow_arrayref){
	my($a, $b) = @$ary_ref;
	print "$a, $b\n";
}
$sth->finish;
$dbh->disconnect;

OKなんだけど、これ、tableで表示するとき、whileが2つになるけど、どうするんだっけ?

print "<table>";
while (my $ary_ref = $sth->fetchrow_arrayref){
	my($a, $b) = @$ary_ref;
	print "<tr><td>$a</td><td>$b</td></tr>\n";
}
print "</table>";

tableはtableで良いんだが。。