#get everything from the table my $statement = "select * from $ref"; my $sth = $dbh->prepare($statement) or die "Couldn't prepare statement: $dbh->errstr"; $sth->execute or die print "Couldn't execute statement: $dbh->errstr"; while ($ref = $sth->fetchrow_hashref){ # must be the first row # print headers if ($count == 1){ print "\t\n"; # get column names foreach $col (keys %{$ref}){ # do not list id field if ($col eq "id") { next; } # save column names for later push @cols, $col; $col = ucfirst $col; print "\t\t$col\n"; } print "\t\n"; } print "\t\n"; #using column names (key) print hash value foreach $col (@cols){ print "\t\t"; print $ref->{$col}; print "\n"; } $count++; print "\t\n"; } print "\n";