Nikhil
Nikhil

Reputation: 586

How to read my own configuration file in perl

How do I read my own configuration file with .pl extension? I have used require to read that file in my script. But I am not sure is this the right way to do it? Can you please suggest me how to do this?

And also when I read the config file with require in my script, I get the errors like Global symbol requires explicit package name. How to solve this?

Here is the example:

This is my config file:

$USERNAME="sach";
$PASSWORD="sach123";
$DBNAME="personal";
$HOST="localhost";
$LIST_OLD_FILES_FILE="old_files.txt";
$remove_files=1;
$File_path="/sach/";

And here is how I call it in my script:

require "config.pl" ;
$dbh = DBI->connect("DBI:mysql:$DBNAME:$HOST",$USERNAME,$PASSWORD) or 
     die "$dbh->errstr\n";

Upvotes: 1

Views: 5794

Answers (1)

Brant Olsen
Brant Olsen

Reputation: 5664

You can use the do command to read in a configuration file with perl code in it.

do 'config.pl';

Upvotes: 4

Related Questions