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

I want all to be in one folder, including the script, MySQL database, module, and etc. The problem is MySQL and the module, how to change MySQL path so that it find the database in the current folder, and to change @INC to reffer to the current folder. I transfer all my module and database in one folder but it wouldn't work. But when i transfer back to where it originally belong it work ok again.

I need it to be in one folder in order for me to easily submit my assingment and for the lecture to evaluate it easily. TQ

Replies are listed 'Best First'.
Re: MySQL and PERL
by tachyon (Chancellor) on Jul 20, 2004 at 07:41 UTC

    For the @INC issue just do:

    use lib './'; # put current dir into @INC

    For MySQL it would seem unlikely that your assignment requires a running copy of MySQL wrapped with it. This makes no sense. You can change the data path via starting mysql with --datadir=/path/to/datadir or by changing the the config options in /etc/my.cnf

    [mysql.server] user=mysql basedir=/var/lib

    Changing /etc/my.cnf is not going to work as this is not in your folder. Even if you could, either possible option to change the data path requires a server restart. It makes a lot more sense to use mysqldump or mysqlhotcopy to dump your DB and then just have a little shell/perl sctipt to create the DB and insert the data into a local MySQL. If you need one file stand alone functionality I sugges DBD::SQLlite is a better option.

    cheers

    tachyon

      From perlfaq1:

      What's the difference between "perl" and "Perl"?

      One bit. Oh, you weren't talking ASCII? :-) Larry now uses "Perl" to signify the language proper and "perl" the implementation of it, i.e. the current interpreter. Hence Tom's quip that "Nothing but perl can parse Perl." You may or may not choose to follow this usage. For example, parallelism means "awk and perl" and "Python and Perl" look OK, while "awk and Perl" and "Python and perl" do not. But never write "PERL", because perl is not an acronym, apocryphal folklore and post-facto expansions notwithstanding.

      (my emph.)

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

        Must be my Win32 background. I am not case sensitive. I find argumants about perl, PERL, Perl a waste of time. However I find the fact that anyone makes the claim that PERL does not stand for Practical Extraction and Reporting Language to be *historically inaccurate*. Download the original Perl 1 source from here Within it you can easily grep the man page which is:

        .TH PERL 1 LOCAL .SH NAME perl - Practical Extraction and Report Language .SH SYNOPSIS .B perl [options] filename args .SH DESCRIPTION .I Perl is a interpreted language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports bas +ed on that information.

        You may note that in the first 5 lines Larry himself uses PERL, perl and Perl as well as using the capitalisation Practical Extraction and Report Language.

        So call it what you want and say it means whatever you like. Does it *really* matter? Can I extract one gram worth of extra meaning from how someone capitalises pErL? OK so that looks script kiddie to me :-) Could you blame Larry for the 'confusion' by using PERL, perl, Perl, and Practical Extraction and Report Language in the first 5 lines of the original man page.

        cheers

        tachyon

Re: MySQL and PERL
by davidj (Priest) on Jul 20, 2004 at 07:32 UTC
    Well, there are a couple of problems, here.

    First, and foremost, you appear to have an instructor who gave you a Perl/MySQL assignment but 1) failed to provide any instructions for how to turn it in, or 2) failed to provide a mechanism for the assignment being evaluated. (That is something you might want to consider the next time you take a class).

    The other 2 issues are not hard to resolve.
    1) to modify the @INC array, use the use lib; directive at the beginning of your script:
    BEGIN { use lib "/path/to/your/folder"; }

    2) to resolve the database issue, you can use the --datadir switch when you start up the server:
    <mysql server> --datadir=/path/to/your/folder
    That should do it

    davidj