Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting up addressability to vars in an "included" file 1

Status
Not open for further replies.

RPrinceton

Programmer
Jan 8, 2003
86
US
Hi,
I am still in the process of coming up with best practices with regard to Perl. I am processing the same database in many scripts. Obviously for brevity the database variables
should remain the same throughout the scripts. I decided to put all of the database variables in a file, to be included in those scripts that required database processing. This will cut down on errors due to typos. The 'use' and 'require' allow my external file named dbinc.pm to be included in my main program. I know I can access the variables in file dbinc.pm by using the $dbinc::varnm syntax. I would like to not have to qualify every reference to a variable with dbinc::. Is there a way to accomplish this...perhaps something like use dbinc qual=>dbinc or some such thing at the time of including the file? Please advise. Thanx in advance. Regards,
Randall Princeton
 
Hi.
I'm not sure exactly what you're asking.
However you can put all of your variables into a
perl pl file all by themselves, and then use the require
statement to 'import' them into your current script.
For example if you have a file named variable.pl
The contents of that file looks something like this :

$DatabaseFilename="mydatabase.mdb";
$TotalRecords="10";
$Version="1.0";
1; ## <---- Always close the file with this.

Any line of text in the variable.pl file must be valid perl.
Then in any script that you need to access these variables
just enter this line somewhere near the top:

require 'variable.pl';

You now have full acess to the variable names and any
settings that you may have pre-defined.

Crackn101
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top