http://www.perlmonks.org?node_id=988938

chefchanyu has asked for the wisdom of the Perl Monks concerning the following question:

Hi: How can I separate the undef data and NULL data? the following code work ok for undef/null data but Iwon't know which one is undef and which is null they all print out " ".
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"; }