use strict; use DBI; use Data::Dumper; my $dbh = DBI->connect("dBi:mysql:cacti:localhost", "cacti", "cacti") or die("Cannot connect: $DBI::errstr\n"); my $sth = $dbh->prepare("select * from data_template_data"); $sth->execute; my $names = $sth->{NAME}; for (@$names) { printf("%-10s",$_); } print "\n"; while (my $row_ref = $sth->fetch()) { for (@$row_ref) { if (defined($_)) { printf("%-10s",$_); } # elsif ($_ eq '') # { # print 'NULL'; # } elsif (undef($_)) { print "\' \'"; } } print "\n"; }