0

I'm currently trying to run NERVE a vaccine development program that is made up of Perl scripts and have trouble getting it to run properly. I've downloaded and installed all prerequisites but every time I reach the mysql step of the code, it crashes, and an error message says: Can't locate object method "connect" via package "Mysql" (perhaps you forgot to load "Mysql"?) at ./NERVE line 340, line 5. I took a look at the code and changed "use mysql" to "use DBI" and "use DBD:mysql" but then I get the error: Can't use string ("") as a HASH ref while "strict refs" in use at /usr/local/lib/perl/5.14.2/DBI.pm line 604, line 5.

I would appreciate if anyone could look the code over for the mysql section and give me advice on how to fix it so I can run the program properly. I tried emailing the developers but no response so I'm hoping you guys can help me.

Below is the perl code for NERVE for the mysql section.

    use mysql;
$db=Mysql->connect("$host","$database","$user","$password");
if(!$db || (!$host || !$database || !$user || !$password)){
    print "\nAttention: mysql connection parameters are missing or not correct!\n";
    print "I need you to specify: host, database, user, password;\n";
    print "You can do it now typing them right in that order and separeted only by comma;\n";
    print "For example:localhost,Pathogens,sandro,xvzhs\n";
    print "So, your Mysql connection settings are (type q to quit):";
    while (!($db && $mysql =~ /,/) & $mysql ne "q"){
        chomp($mysql = <STDIN>);
        die "Ok,let's quit this work! Call me when your mind is clearer about Mysql parameters! Bye :-)\n" if $mysql eq "q";
        ($host,$database,$user,$password) = split (',',$mysql);
        $db=Mysql->connect("$host","$database","$user","$password");
        last if($db && $mysql =~ /,/);
        print "\nMysql connection settings still not correct!\n";
        print "Remember: host, database, user, password, separeted only by comma.\n";
        print "For example:localhost,Pathogens,sandro,xvzhs\n";
        print "Please, try again:";
    }
    print "Ok, Mysql connection to \"$database\" database was successful!\n";
}
  • 4
    Yuck. [`Mysql.pm` has been obsolete since 1998.](https://metacpan.org/pod/release/CAPTTOFU/DBD-mysql-3.0008/lib/Mysql.pm#OBSOLETE-SOFTWARE) You should read the [`DBI` documentation](https://metacpan.org/pod/DBI) thoroughly, since its interface is different from `Mysql.pm` and your code will need to be updated accordingly (i.e. you can't just replace `use Mysql;` with `use DBI;` and expect it to work). I would start by reading the [outline usage](https://metacpan.org/pod/DBI#Outline-Usage) section. – ThisSuitIsBlackNot Jan 13 '15 at 21:38
  • 1
    Having said that, if this is one of those horrible million-line monstrosities also known as "legacy code" *(shudder)*, and updating it is not an option, simply change your `use` statement to `use Mysql;` with a capital `M`. Perl is case sensitive. – ThisSuitIsBlackNot Jan 13 '15 at 21:49
  • Yes the "use mysql" was originally "use Mysql" but it gave me the error: Can't locate Mysql.pm in @INC (@INC contains: /usr/lib/perl5/DBD /usr/lib/perl5/DBD/mysql /usr/lib/perl5/DBI /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at ./NERVE line 339. BEGIN failed--compilation aborted at ./NERVE line 339. – user3617208 Jan 13 '15 at 21:54
  • Is there a package I can download for Mysql to work instead of mysql? I'm running Debian 7 right now. Sorry for all the questions, I'm new to all this programming and Linux stuff. – user3617208 Jan 13 '15 at 21:57
  • `Can't locate Foo.pm in @INC` usually means that the module isn't installed. See [What's the easiest way to install a missing Perl module?](http://stackoverflow.com/questions/65865/whats-the-easiest-way-to-install-a-missing-perl-module) for instructions on installing. However, since `Mysql.pm` is obsolete, I would highly recommend switching to `DBI`, but you'll need to read the documentation I linked above and change your code accordingly. – ThisSuitIsBlackNot Jan 13 '15 at 22:04
  • @user3617208, Your `@INC` is messed up. `/usr/lib/perl5/DBD`, `/usr/lib/perl5/DBD/mysql` and `/usr/lib/perl5/DBI` shouldn't be in there. DBI and DBD::mysql will be found if `/usr/lib/perl5` is present. – ikegami Jan 13 '15 at 22:06
  • Does Foo.pm equate Mysql.pm? Just curious because I've got DBD and DBI installed so I see a mysql.pm file. Which was why I thought I had everything installed. To install Mysql.pm do I just download the Belgian::Chocolate package? – user3617208 Jan 13 '15 at 22:13
  • 1
    The nerve software was originally published in 2006. If you really want to use it now, ask the original authors about a modern version. Just my 2 cents. – dgw Jan 13 '15 at 22:13
  • And the @INC has /usr/lib/per5/DBD and all the other ones were oon it because I had to grab mysql.pm before and that was located in those folders. – user3617208 Jan 13 '15 at 22:14
  • @user3617208 `mysql.pm` is [`DBD::mysql`](https://metacpan.org/pod/DBD::mysql), which is completely different from `Mysql.pm`. If you already have `DBI` and `DBD::mysql` installed, your `use` statement should be `use DBI;` (not `use mysql;` and not `use DBD::mysql;`). Read the `DBI` documentation for more details on how to use it properly. – ThisSuitIsBlackNot Jan 13 '15 at 22:17
  • @user3617208, Yes, I know why you did it, and it was wrong. – ikegami Jan 13 '15 at 22:21

1 Answers1

2

The error message is correct. You are attempting to use a module named , but you never loaded it. Change

use mysql;

to

use Mysql;

to use that module. In the comments, you mention that results in

Can't locate Mysql.pm in @INC 

Unless you have reason to believe the module is installed, that indicates it needs to be installed[1]

That module used to be part of the DBD-mysql distribution, but it's obsolete. It's so ancient it was removed from DBD some years ago. To obtain it, you will need to downgrade your DBD-mysql distribution to version 3.0008.

That's pretty awful thing to do. The script should have DBI instead.


cjm points

since the Mysql.pm in 3.0008 is just a compatibility layer using DBI under the hood, you should be able to install Mysql.pm & Mysql/Statement.pm from that old dist along with a current DBD-mysql.

So if you extract Mysql.pm from the distro I linked above as /usr/lib/perl5/Mysql.pm and Mysql/Statement.pm as /usr/lib/perl5/Mysql/Statement.pm, you should have an easy pain-free solution.


  1. In newer versions of Perl, the error message has been improved. It now reads as follows:

    Can't locate Mysql.pm in @INC (you may need to install the Mysql module)
    
ikegami
  • 367,544
  • 15
  • 269
  • 518
  • Forgot you weren't debugging your own code. Updated the answer. – ikegami Jan 13 '15 at 22:35
  • 1
    Actually, since the `Mysql.pm` in 3.0008 is just a compatibility layer using DBI under the hood, you should be able to install Mysql.pm & Mysql/Statement.pm from that old dist along with a current DBD-mysql. – cjm Jan 14 '15 at 02:31
  • Incorporated @cjm's comment with a few extra details into my answer. – ikegami Jan 14 '15 at 03:25