Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: Use of uninitialized value in require at ...AutoLoader.pm ?

by jvector (Friar)
on Oct 24, 2008 at 08:49 UTC ( [id://719288] : note . print w/replies, xml ) Need Help??


in reply to Re^3: Use of uninitialized value in require at ...AutoLoader.pm ?
in thread Use of uninitialized value in require at ...AutoLoader.pm ?

Apparently Autoloader is doing require undef; if there is an undef value in @INC when DBI's connect method is called.

This code generates the warning if the line push  @INC,$ENV{'PERL5LIB'}; is executed before the call to DBI->connect. It's not clear what the push  @INC,$ENV{'PERL5LIB'}; is actually meant to be doing (this code has been copied from a system that was built several years ago).

The code connects to an Oracle database. Obviously it will not work with someone else's Oracle DB. If you do not have an Oracle database I do not know if the same issue shows up with other DBD drivers. I did see the same Autoloader warning appearing when I ran the code with invalid connect parameters, but don't know what was being complained about.

#!/usr/bin/perl use strict; use warnings; use diagnostics -warntrace; # the -warntrace does not seem to help B-( use DBI; sub db_connect; my $Odbh; # database handle returned by connect to Oracle print "$0: ",(scalar localtime), "\n"; #exit; #no warn if exit before db_connect call &db_connect; exit; # yes warn if exit after connect print "$0: " ,(scalar localtime), " run complete\n"; $Odbh->disconnect; #exit; # yes warn if exit after connect + disconnect ################ sub db_connect { ################ my ($dsn, $dbuser, $dbpassword) = ("DBI:Oracle:qq3","nn2","nn2"); # # Connect to Oracle # # if the push on the next line is commented out there is no warning. push @INC,$ENV{'PERL5LIB'}; # location of libs for DBD::Oracle print "ENV= [",join ("]\n[",@INC),"]\n"; $Odbh = DBI->connect($dsn, $dbuser, $dbpassword, { RaiseError => 1, AutoCommit => 1 }) or warn "Can't connect to $dsn: $DBI::errstr"; }

This signature will be ready by Christmas

Replies are listed 'Best First'.
Re^5: Use of uninitialized value in require at ...AutoLoader.pm ?
by ikegami (Patriarch) on Oct 24, 2008 at 09:01 UTC

    If that's true, it's just a little case of GIGO that can be fixed by making the push conditional.

    push @INC, $ENV{'PERL5LIB'} if exists($ENV{'PERL5LIB'});
      Probably worth seeing if that push is even still necessary. This code has sat there while several generations of Oracle have come and gone. It may be the residue of one of those hoops that had to be jumped through to get Oracle+DBD to run on Red Hat long ago that are no longer required.

      This signature will be ready by Christmas