Page 1 of 1

Webmin / MySQL / DBD::mysql - undefined variable Perl error.

Posted: Fri Oct 31, 2003 2:07 pm
by jasonb
I recently upgraded to the latest Perl module of DBD::mysql (2.9002). After having done so, I discovered that I was unable to access the "Permission" sub-modules of Webmin's MySQL interface. When trying to do so, I got some kind of error message involving Perl, a hash, and not being able to use an undefined variable on line 113 of /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi/DBD/mysql.pm.

After trying to reinstall the Perl module to no better effect, I finally stumbled onto the solution. Here's what that section of code, from that file, looks like:

Code: Select all

# create a 'blank' dbh
my($this, $privateAttrHash) = (undef, $attrhash);
$privateAttrHash = { %$privateAttrHash,
    'Name' => $dsn,
    'user' => $username,
    'password' => $password
};
Line 113 is the line that starts "$privateAttrHash". I have only a general idea of what this bit of code means (I know it's a way of defining an array variable with information about the database that's being accessed). However, when trying to troubleshoot "undefined variable" that one thing that stood out was the "(undef, $attrhash)" section of code. "Undef", to me, read a lot like "undefined".

So, I tried the trial and error method of replacing "undef" with "def" - thinking, in a very uneducated, shot in the dark fashion, that this might actually define the variable. To my total amazement this actually worked. After having done that, Webmin works just fine when I use the "Permission" sub-modules.

I'm left wondering why the latest version of module would, by default, do something so silly as to declare a variable without defining it, and causing other things to break. I'm equally confused that this would even be a possibility - if you declare a variable you should, by default, be defining it - shouldn't you?

Posted: Sat Nov 01, 2003 2:14 pm
by jasonb
Oops - not so fast.

While this fixed Webmin, it broke Movable Type (my blog software).

With this change, when I try to access the administrative portion of MT, I get an error message about a "bare def". Changing it back again (to "undef") allows Movable Type to work again.

So - either Webmin works or Movable Type works, but not both. This pretty much sucks...

Posted: Sat Nov 01, 2003 6:12 pm
by jasonb
Okay, problem solved.

I re-installed the older version of the module and checked the code there. Then I reinstalled the new version again and simply replaced the new code with the old code which looked like this:

Code: Select all

# create a 'blank' dbh
   my($this, $privateAttrHash);
   $privateAttrHash = {
       'Name' => $dsn,
       'user' => $username,
       'password' => $password
   };
Everything now works again without any errors.