Hi Tony,

Have you tried 

Use Config::IniFiles;
# Openin of Configuration File
$ini = new Config::IniFiles( -file => $IniFile);

# Pick up Parameters from .ini File
$Param1 = $ini->val("Configuration", "Param1");
$Param2 = $ini->val('Configuration', 'Param2');
$Param3 = $ini->val('Configuration', 'Param3');
$Param4 = $ini->val('Configuration', 'Param4');

And so on...


Br
        Ari Wilen


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Tony
White
Sent: Friday, June 04, 2004 11:11 PM
To: Activeperl (E-mail); Perl-Win32-Users (E-mail)
Subject: Inventive ways to parse configuration files?


I'm used to parsing config files by slurping in a conf file one line at
a time and then breaking the line up into the keys and values of a hash.
This works fine for single-line configuration options of the form "key =
value".  But I'd like to handle more complicated configuration options
of the form:
        key = {key1 = value1; key2 = value2; ... ; keyN = valueN}

I began to think of the solution to this problem in my "old way," but
then realized it might be possible to simply slurp in the whole damn
file and eval() it, assuming the config file follows Perl conventions.
For example, given a conf file that looks like:

        #------- conf file example ---------
        $log_file = 'c:/scripts/dumpspam.log';
        $mail_cfg = { mbox1 => 'Tony', mbox2 => 'Alan' };
        #------- conf file example ---------    

and code that looks like this:
        #------- code ---------
        my $separator = $/;
        $/ = undef;
        my $cfg = {};

        open( FH, "conf" ) or die;
        $_ = <FH>;
        
        eval( $_ );
        
        print "$log_file\n";
        print "$mail_cfg->mbox1\n";

        close FH;

        $/ = $separator;
        #------- code ---------

I've tried a small test of the above, but it doesn't work.  Perhaps
eval() can handle only single statements?

Anyway, does anyone have any neat ideas on how to handle this?  TIA

Tony White
twhite_AT_seventhwavetech_DOT_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

Reply via email to