called too early to check prototype at

Discussion in 'Perl Misc' started by Ron Eggler, Mar 18, 2008.

  1. Ron Eggler

    Ron Eggler Guest

    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
    --
    chEErs roN
     
    Ron Eggler, Mar 18, 2008
    #1
    1. Advertising

  2. Ron Eggler <> wrote:
    >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
     
    Jürgen Exner, Mar 19, 2008
    #2
    1. Advertising

  3. Ron Eggler

    Ben Morrow Guest

    Quoth 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"));


    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
     
    Ben Morrow, Mar 19, 2008
    #3
  4. Ron Eggler

    Ron Eggler Guest

    Jürgen Exner wrote:

    > 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!
    --
    Ron
     
    Ron Eggler, Mar 19, 2008
    #4
  5. Ron Eggler

    Dr.Ruud Guest

    Jürgen Exner schreef:

    > for my $count (0..@dbset-1)



    Alternatives:

    for my $count ( 0 .. $#dbset )

    for my $count ( $[ .. $#dbset )

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Mar 20, 2008
    #5
  6. Ron Eggler

    J. Gleixner Guest

    Ron Eggler wrote:
    > J�rgen Exner wrote:
    >
    >> 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.
     
    J. Gleixner, Mar 20, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kostia

    Sesson_End called too early

    Kostia, Oct 21, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    432
    Kostia Grebelsky
    Oct 21, 2004
  2. graphicsxp

    Session expired too early

    graphicsxp, Jul 4, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    494
    graphicsxp
    Jul 4, 2006
  3. Scott Robinson

    Socket being garbage collected too early

    Scott Robinson, Dec 16, 2004, in forum: Python
    Replies:
    4
    Views:
    413
    Scott Robinson
    Dec 18, 2004
  4. Lars Uffmann

    Is it too early to cheer?

    Lars Uffmann, May 19, 2008, in forum: C++
    Replies:
    0
    Views:
    296
    Lars Uffmann
    May 19, 2008
  5. Filip Gruszczyński

    Too early implementation

    Filip Gruszczyński, Apr 18, 2009, in forum: Python
    Replies:
    9
    Views:
    313
    Aaron Watters
    Apr 19, 2009
Loading...

Share This Page