in reply to Re: Can't call method "prepare" on an undefined value
in thread Can't call method "prepare" on an undefined value

I've played around with "strict" and "my", and funny enough, it doesn't fix the problem. I have found something else now... If I do not use procedures, ie. I do my mySQL connection, executing the SQL statement and disconnecting it all in one piece of code, it works fine, however, I'm using procedures to do that. I have a connection procedure, a disconnection procedure, and a SQL execution procedure. It looks like my $mwsdbh variable I receive from my connection is not a global variable, although it should be. When it comes to the execution of SQL statement procedure, the script dies.

Have you guys seen this behaviour before? I've tried "returning" the variable, but that doesn't work.

Thanks!

#!/massyn.pl The more I learn, the more I realize I don't know. Albert Einstein 1879-1955

  • Comment on Re: Re: Can't call method "prepare" on an undefined value

Replies are listed 'Best First'.
Re: Re: Re: Can't call method "prepare" on an undefined value
by CountZero (Bishop) on Dec 18, 2002 at 10:41 UTC

    Did you try sending the $mwsdbh variable as a parameter to the subroutines?
    That way it should be known and accessible in the subroutines.

    I'm still confused about the use you make of the "local" keyword for the declaration of your variables inside the subroutine. If you have a moment to spare, could you explain it?

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      I'm using local, so that the variables defined only stay within that procedure. They don't need to be global variables.

      As for your suggestion of passing the variable out, that didn't work. I guess that $mwsdbh is not really a scalar. How can I reference it properly?

      #!/massyn.pl The more I learn, the more I realize I don't know. Albert Einstein 1879-1955

        1. As per the Camel Book (3 ed.) p. 994 the local operator is used to localize a global variable within a dynamic scope.

          Use my for local variables whenever you can get away with it. Using local merely gives you a temporary value to a global variable. (the Camel Book (3 ed.) p. 588)

        2. Did you declare $mwsdbh also as a local initially? If you leave the scope it was declared in, it looses its local value.

        3. You can pass anything out to a subroutine: scalars, arrays, hashes, references, ...

          As long as the subroutine reads it back in through @_ in the right order it cannot be the cause of your problem. Can you post your code with the passing of the $mwsdbh variable to the subroutine and the way the subroutine used it?

        CountZero

        "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law