my $query = "SELECT id,fname,lname FROM test WHERE id < 10"; my @fields = qw(id fname lname); # create a list of cols values my @cols = (); @cols[0..$#fields] = (); $sth = $dbh->prepare($query); $sth->execute; # Bind perl variables to columns. $sth->bind_columns(undef, \(@cols)); print "
| $_ | ", @fields), "
|---|
| $_ | ", @cols), "