Here is a snippet of code that I use:
my %config;
if (-e "$filepath\\config") {
open CONFIG, "<$filepath\\config" or die "Unable to open config file:
$!\n";
while (<CONFIG>) {
next unless /^[A-Za-z]/; # this assumes your keys all start with letters
chomp;
my ($key,$value) = split(/\=/);
$config{$key} = $value;
}
close CONFIG;
}
else {
print "No config file found!";
exit 1;
}
An example config file would be:
PATH = D:\Path\To\Data\Files
LOGDIR = D:\Path\To\Logdir
Then any config variable can be retrieved by getting the hash value like
this:
$path = $config{PATH};
$logdir = $config{LOGDIR};
Hope this helps.
TKind regards,
Trevor J. Joerges
--------------------------------------------
$_=q;rrUSFWPSZK.ZKPFSHFT,rkvtuZbopuifsZQZibdl
rrqpxfsfeZcyZQ,,riuuq://xxx.%.dpn,ru~@%.dpn ,rrr8-)
;;s;\~;kpfshft;g;s;\%;tfoenjnf;g;y;B-x;A-w;;
s;P;perl;g;s;,;\n;g;s;Y; ;g;s;q;\t;g;print;
--------------------------------------------
----- Original Message -----
From: "Praveen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, September 19, 2002 7:36 AM
Subject: Appconfig
| Hi,
|
| Can anyone give an example how to read the
| configuration file(environment variable file) using
| perl, I was reading the AppConfig documentation, and I
| tried, its not working.
|
| for e.g., I have a file called gouenv
| in that I declared variables
|
| mydev = stmt_proc
| mypass = tryme
|
| how to read the above file and store in a variables
| using AppConfig.
|
| Thanks
| Goutam
|
| =====
| Goutam Siddavarapu
| 614-537-8406(Cell)
| 614-677-9750(W)
| http://www.Siddavarapu.com
|
| __________________________________________________
| Do you Yahoo!?
| New DSL Internet Access from SBC & Yahoo!
| http://sbc.yahoo.com
| _______________________________________________
| ActivePerl mailing list
| [EMAIL PROTECTED]
| To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
|
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs