There are a number of ways, and here are two popular ones:
1) A seperate config file:
Filename example: /etc/myperlconf
Content:
Code:
$dbusername = "root";
$dbpassword = "";
1;
To include in perl:
Code:
require "/etc/myperlconf";
2) A seperate perl file containing var declerations as well as common functions:
Filename example: /var/www/cgi-bin/common.pl
Content:
Code:
sub dbconnect {
$dbusername = "root";
$dbpassword = "";
$dbname = "test";
$db = "dbi:mysql:" . $dbname;
$dbh1 = DBI->connect( $db, $dbusername, $dbpassword ) or die("DB ERROR : $!");
$dbh2 = DBI->connect( $db, $dbusername, $dbpassword ) or die("DB ERROR : $!");
$dbh3 = DBI->connect( $db, $dbusername, $dbpassword ) or die("DB ERROR : $!");
}
sub decode {
if ( $ENV{'REQUEST_METHOD'} =~ /get/i ) { $buffer = $ENV{'QUERY_STRING'}; }
else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n/ /g; # added to strip line breaks
$value =~ s/\r//g;
$value =~ s/\cM//g;
$FORM{$name} = $value;
}
}
1;
In your perl scripts, use the following:
Code:
require "/var/www/cgi-bin/common.pl";
dbconnect();
decode();
You can use the above code in all the Perl scripts that form part of the application.
Hope that helps
Cheers