For instance, all my scripts will be contained in the dir:
/includes/
Each Perl function I make will be in its own file in that dir.
The config file will be located at /includes/config.cgi
The only file that will have information about my database, such as location of the server, usernames and passwords will be that config.cgi file. I would like to set it up so that all files will reference this config file at the top. How would I go about doing this? I tried "use includes::config;" but that didn't work. Is there something else I need to do?
As well, all the other files will be referenced by other html files in the root dir.
So if I have "/input.html" that recieves 2 variables, on submit, those two variables will go into "/includes/process.cgi", and then new variabes will be returned to "/output.html". How would I go about doing this?
mysql.pl
sub databaseConnect {
my $DBuser="mysql";
my $DBpass="";
my $databaseName = "dbi:mysql:databaseName";
$dbh = DBI->connect($databaseName, $DBuser, $DBpass) ¦¦ die $DBI::errstr;
$dbh->{mysql_auto_reconnect} = 1;
# clear values for security reasons.
$DBuser="";
$DBpass="";
}
1; # vital
then just use this in your main file:
require "includes/mysql.pl";
databaseConnect(); # $dbh comes from this;
In general, use Module () is recommended over require Module, because it determines module availability at compile time, not in the middle of your program's execution. An exception would be if two modules each tried to use each other, and each also called a function from that other module. In that case, it's easy to use require instead.
Docs [search.cpan.org]