1

I am using number of perl scripts in my web project, which I am calling through jquery ajax calls. Each perl script contains mysql database connection information (user_name, password, database name).

Is there any better way, so that I can avoid database connection information in each perl file, and can store that globally, without any security issues.

1
  • 1
    may be to store it in one config file? something like config.yml Commented Oct 4, 2013 at 7:53

2 Answers 2

2

config.pl

{ 
  # sql credentials
  user => "sqluser", pass => "123", dsn => "mysql..",
}

index.pl and other scripts:

my $CFG = do "config.pl";
print "$CFG->{user} $CFG->{pass} ...\n";
Sign up to request clarification or add additional context in comments.

Comments

2

A bit more perlish option:

Config.pm

package Config;

sub get_config {
  return { 
    # sql credentials
    user => "sqluser", pass => "123", dsn => "mysql..",
  };
}
1; #return true from modules

index.pl and other scripts:

#make sure the current folder is in the lib path
#(if you have all in the same folder).
use FindBin; 
use lib $FindBin::Bin;

require Config;
my $cfg = Config->get_config();
print "$cfg->{user} $cfg->{pass} ...\n";

But I guess you got the consept, and TMTOWTDI.

1 Comment

Config already exists, choose another name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.