Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Global symbol "$DBI" requires explicit package name

by NateTut (Deacon)
on Dec 07, 2010 at 18:16 UTC ( #875852=perlquestion: print w/ replies, xml ) Need Help??
NateTut has asked for the wisdom of the Perl Monks concerning the following question:


Why am I getting this error? This code has worked for me many times in the past. This is on ActiveState 5.10, but I tried it on 5.12 and got the same error.



use strict; use warnings; use Data::Dumper; use DBI; use DBD::ODBC; $|++; my $DSN = $ARGV[0]; my $UserName = $ARGV[1]; my $PassWord = $ARGV[2]; my $dbh = DBI->connect("dbi:ODBC:$DSN", $UserName, $PassWord, { R +aiseError => 1, AutoCommit => 1 }) or die "Couldn't connect to:\[$DSN +\] as \[$UserName\]: $DBI->errstr"; my @SELRow; my $SQL_Statement = " Select * From DBC.DBCInfo ; "; my $SELh = $dbh->prepare($SQL_Statement); $SELh->execute; while(@SELRow = $SELh->fetchrow_array) { print("$SELRow[0]:$SELRow[1]\n"); } $SELh->finish(); $dbh->disconnect(); print(Dumper(\@SELRow));


Solved!
changed: $DBI->errstr to $DBI::errstr Thanks AnonyMonk!

Comment on Global symbol "$DBI" requires explicit package name
Select or Download Code
Re: Global symbol "$DBI" requires explicit package name
by Anonymous Monk on Dec 07, 2010 at 18:26 UTC
    Kinda doubt it
    use strict;
    use diagnostics;
    print "$DBI->errstr";
    print "$DBI->errstr";
    __END__
    Global symbol "$DBI" requires explicit package name at - line 3.
    Execution of - aborted due to compilation errors (#1)
        (F) You've said "use strict" or "use strict vars", which indicates
        that all variables must either be lexically scoped (using "my" or "state"),
        declared beforehand using "our", or explicitly qualified to say
        which package the global variable is in (using "::").
    
    
      I swear on my mother's grave (well she's not dead yet, but you get the picture) that I have been using this code for years without a problem. Did something change in DBI?

        This has nothing to do with DBI. You were using a variable you didn't declare ($DBI), and you asked to make such things errors by using (use strict;).

        While $DBI::errstr is also a variable you didn't declare, use strict; forgives qualified ("::") package variables.

        Although it's not documented, DBI->errstr might work. Maybe that's what you were using.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://875852]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (15)
As of 2014-12-18 16:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (58 votes), past polls