called too early to check prototype at

R

Ron Eggler

Hi,

I get a "called too early to check prototype at" in my script and i have no
idea what this is referring to.It is pointing to this line:
for(my $count = 0; $count < scalar(@dbset); $count++){ which sits on top of
my file and is part of:
use DBI;
#
# Open the DB connection
#
my @dbset=(xmlparse($nemsconf,"DBNAME"));

for(my $count = 0; $count < scalar(@dbset); $count++){
my $myDBI = 'DBI:mysql:' . $dbset[$count] . ':localhost';
my $dbh = DBI->connect($myDBI,'root','novax')
or die "Couldn't connect to database: " . DBI->errstr . "\n";

Any idea what could be wrong here?

Thank you!
Ron
 
J

Jürgen Exner

Ron Eggler said:
Hi,

I get a "called too early to check prototype at" in my script and i have no
idea what this is referring to.It is pointing to this line:
for(my $count = 0; $count < scalar(@dbset); $count++)

This can be rewritten in a much easier to read way as
for my $count (0..@dbset-1)
for(my $count = 0; $count < scalar(@dbset); $count++){
my $myDBI = 'DBI:mysql:' . $dbset[$count] . ':localhost';
my $dbh = DBI->connect($myDBI,'root','novax')
or die "Couldn't connect to database: " . DBI->errstr . "\n";

However, as you don't do anything with $count but to index the array in a
linear fashion it is even easier to use a simple

for(@dbset){
my $myDBI = "DBI:mysql:$_ :localhost";
....

jue
 
B

Ben Morrow

Quoth Ron Eggler said:
Hi,

I get a "called too early to check prototype at" in my script and i have no
idea what this is referring to.It is pointing to this line:
for(my $count = 0; $count < scalar(@dbset); $count++){ which sits on top of
my file and is part of:
use DBI;
#
# Open the DB connection
#
my @dbset=(xmlparse($nemsconf,"DBNAME"));

Have you by any chance declared xmlparse below like this

sub xmlparse() {

? This is not how you declare a Perl sub. Remove the ().

If not, you will need to reduce your problem to a *small*
*self-contained* program *we can all run*, or we can't help you.

Ben
 
R

Ron Eggler

Jürgen Exner said:
for(@dbset){
my $myDBI = "DBI:mysql:$_ :localhost";

Alright,

Thanks for that but when i try it like this:
#
# Open the DB connection
#
my @dbset=(xmlparse($nemsconf,"DBNAME"));
print "DB name: ". xmlparse($nemsconf,"DBNAME")."\n";
#for(my $count = 0; $count < scalar(@dbset); $count++){
# my $myDBI = 'DBI:mysql:' . $dbset[$count] . ':localhost';
for(@dbset){
my $myDBI = "DBI:mysql:$_ :localhost";
my $dbh =
DBI->connect($myDBI,xmlparse($nemsconf,"DBUSER"),xmlparse($nemsconf,"DBPASS"))
or die "Couldn't connect to database: " . DBI->errstr . "\n";
}

It's telling me only:
[shell]
DB name: toronto
DBI connect('toronto :localhost','root',...) failed: Incorrect database
name 'toronto ' at ./log_parser.pl line 39
Couldn't connect to database: Incorrect database name 'toronto '
[/shell]
eventho i can connect nicely with:
mysql -u root -p toronto

any idea what could be wrong there?
I first thought where it says "Couldn't connect to database: Incorrect
database name 'toronto '" that would be a mistake because of the space at
the end but when I hardcode "toronto" it is displaaying it the same way. So
I'm pretty stuck here.
Thanks for any further help!
 
J

J. Gleixner

Ron said:
J�rgen Exner said:
for(@dbset){
my $myDBI = "DBI:mysql:$_ :localhost";

Alright,

Thanks for that but when i try it like this:
#
# Open the DB connection
#
my @dbset=(xmlparse($nemsconf,"DBNAME"));
print "DB name: ". xmlparse($nemsconf,"DBNAME")."\n";
#for(my $count = 0; $count < scalar(@dbset); $count++){
# my $myDBI = 'DBI:mysql:' . $dbset[$count] . ':localhost';
for(@dbset){
my $myDBI = "DBI:mysql:$_ :localhost";
my $dbh =
DBI->connect($myDBI,xmlparse($nemsconf,"DBUSER"),xmlparse($nemsconf,"DBPASS"))
or die "Couldn't connect to database: " . DBI->errstr . "\n";
}

It's telling me only:
[shell]
DB name: toronto
DBI connect('toronto :localhost','root',...) failed: Incorrect database
name 'toronto ' at ./log_parser.pl line 39
Couldn't connect to database: Incorrect database name 'toronto '
Remove the space.

my $myDBI = "DBI:mysql:$_:localhost";

And check the value.

print "myDBI=$myDBI\n"; #maybe there's a newline? If so, chomp.
[/shell]
eventho i can connect nicely with:
mysql -u root -p toronto

any idea what could be wrong there?
I first thought where it says "Couldn't connect to database: Incorrect
database name 'toronto '" that would be a mistake because of the space at
the end but when I hardcode "toronto" it is displaaying it the same way. So
I'm pretty stuck here.

Go back to the basics.

use DBI;
my $myDBI = 'DBI:mysql:toronto:localhost';
my $user = 'someuser';
my $pw = 'somepw';
my $dbh = DBI->connect( $myDBI, $user, $pw )
or die "Couldn't connect to database: " . DBI->errstr . "\n";

If that works then verify the values of $user, $pw, and $myDBI are
what you expect.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top