Fetchrow Uninitialized Values

From: seldn (seldn_at_hotmail.com)
Date: 11/30/03


Date: 30 Nov 2003 05:52:08 -0800

Hello all.

I have a script that connects to a PostgreSQL database, executes a
single SELECT, and dumps the results to the screen. Although it works
find, I am getting 'Uninitialized Values' warnings from those rows
that contain NULL values.

I'm aware that some rows will have NULL values but would rather not be
warned about it each time. I've been able to suppress these warnings
by encapsulating the array print in "no warnings;" and "use
warnings;". Is this the appropriate method of dealing with this, or
is there a better option? The code is below.

Thanks for the help,
Seldn

#-----------------------------------------------------

#!/opt/perl/bin/perl
use warnings;
use strict;
use DBI;

my $dbname="testdb";
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname");
unless ($dbh) {die $DBI::errstr}

my $sql = "SELECT * FROM servers";
my $sth = $dbh->prepare("$sql");
unless ($sth) {die $DBI::errstr}

$sth->execute;
while (my @row = $sth->fetchrow()) {
    no warnings;
    print @row;
    use warnings;
}

$sth->finish;
$dbh->disconnect;



Relevant Pages

  • Re: pattern matching
    ... use strict; ... use warnings; ... afkomstige benaming voor een planetoïde die ...
    (comp.lang.perl.misc)
  • Re: Perl Script runs to slow
    ... for my $rawdata { ... use strict; ... use warnings; ... opendir or die $!; ...
    (perl.beginners)
  • Re: die-ing within functions
    ... > I'm looking for some advice on programming style ... ... Unconditionally dying in library routines is bad style anywhere. ... function *does* die inappropriately. ... The pragmatic "warnings" module offers a solution in that it allows the ...
    (comp.lang.perl.misc)
  • Re: Why does Net::SFTP trigger my die handler when no errors?
    ... Kindly consider, if you please, this trivial sample script ... I have defined a custom "die" handler. ... warnings are supressed; OTHERWISE they are ... > Why is Net::SFTP triggering my die handler when nothing seems to be ...
    (comp.lang.perl.misc)
  • RE: Load an hash from a text file
    ... use strict; ... use warnings; ... $file or die qq ... get into object oriented programming you'll use a slightly different ...
    (perl.beginners)