SPUG: parsing a config file
jimfl
jimfl at colltech.com
Fri Jan 7 17:19:37 CST 2000
--On Friday, January 7, 2000 1:37 PM -0800 Todd Wells <toddw at wrq.com> wrote:
> {
> Domain = {
> servers = ();
> status = Enabled;
> };
> Log = {
> easLogLevel = Standard;
> log = On;
> };
> Restart = {
> Condition = 0;
> Enabled = NO;
> RestartTime = {
> CalenderFormat = "%d/%m/%Y %I:%M %p";
> FromTime = "18/07/1997 03:00 AM";
> ToTime = "18/07/1997 06:00 AM";
> };
> Schedule = 0;
> };
> Security = {
> administrator = Administrators;
> domain = MINE;
> manager = Users;
> security = Off;
> user = Users;
> };
> }
This is almost perl. All you have to do is change all occurrances of '='
to '=>', all ';' to ',' and assign it to a variable, with code like:
$cdata = q($Config = );
while ($line = <DATA>) {
$line =~ s/=/=>/g;
$line =~ s/\;/\,/g;
$cdata .= $line;
}
$cdata .= ";";
eval $cdata;
Then you will have a hashref called $Config which you can reference with
code like:
print $Config->{Log}->{easLogLevel};
--
Jim Flanagan Collective Technologies
jimfl at colltech.com http://www.colltech.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
Email to majordomo at pm.org: ACTION spug-list your_address
More information about the spug-list
mailing list