bodmin has asked for the wisdom of the Perl Monks concerning the following question:

As soon as I put the code below into my perl page i get the following error: Use of uninitialized value during global destruction.

use lib '/www/facmedden/perl/lib'; use CGI::Session; use CGI::Simple; use Data::Dumper; $sid = param('sid') || undef; $session = CGI::Session->new ('driver:MySQL', $sid, {Handle => &opendb}); $sid = $session->id;

Any ideas as to what I am doing wrong?

20040223 Edit by BazB: Changed title from 'CGI::Session'

Replies are listed 'Best First'.
Re: Uninitialised value during global destruction
by davido (Cardinal) on Feb 23, 2004 at 09:21 UTC
    Is it possible that the sub opendb() isn't checking for success, and thus, upon failure, is returning an undef 'Handle'?

    If that's the case, it's also possible that as the script is cleaning up and going home (and doing its garbage collection), it's trying to close that undef filehandle.


    Dave

Re: Uninitialised value during global destruction
by bodmin (Sexton) on Feb 23, 2004 at 09:53 UTC

    Figured it out - just in case anyone came accross the same problem:

    I was not closing the session... put in the close statement, now it works.

      begin(rant)

      Aaaaaahhhhh so what you _REALLY_ meant to say was "I get this error which cannot be produced by the code sample I am going to show you because it is incomplete."

      It is rather difficult to be able to make sense of something when incomplete information is given. It is better to give us enough code that it is truly representative of your application or create a test case that shows us explicitly what is going on.

      end(rant)

      jdtoronto

Re: Uninitialised value during global destruction
by jdtoronto (Prior) on Feb 23, 2004 at 09:18 UTC
    I am not sure, a couple of points to ponder though:
    • maybe you should be using CGI::Session::MySQL
    • I don't see you opening the database connection? My recollection is that you need to open the connection before you pass anything to CGL::Session.

    jdtoronto

      My database connection is open - I use a method to open it and return it's handle (&openDB)

      Tried using ::MySQL but to no avail