> Bill Luebkert wrote: 
> 
> Michael Higgins wrote:
> > Hello, Gurus --
> > 
> > I'm stuck finding the best approach to parsing a config file.
> > 
> > Some configuration items are grouped, nested, in matching 
> braces '{}'. Some
> > are item = value.
> > 
> > I need to modify and replace three sections that are in this format
> > item{.....item{....}}, capturing up to the matched brace.
> > 
> > Any suggestions? 
> 
> Sample config file as currently is:

Like this:

DEBUG = OFF
THRESHOLD = 4
SERVER = .
USER = BATCH
PASSWORD = PASSWORD
Over Write = OVER WRITE
BATCH TASK{
        TASK NAME = The Task
        SLEEP TIME{
                SECOND = 10
        }
}
. . .

and similar. This first '{' starts nested data structures like above. They
all match up.

> 
> Sample config file that you want to change to instead of 
> brace version:
> 

Actually, I think I want to parse this one into a perl structure, change a
few items and write it back out mostly unchanged. Right now, I'm pulling the
bits to change with a bunch of substrs and regexen. It's ugly, but it will
work. I think I should be able to get something more elegant, like a bunch
of hash and array refs, automagically. ;-)

> Any pertinent rules in detail.

I don't know, exactly. Lines are either 'ITEM = VALUE' or begin a config
block like 'ITEM{' -- the same rules inside the block. The braces all match
up but 'ITEM = VALUE' can appear inside the blocks too.

Basically, I thought to use something like Parse::RecDescent or
Text::Balanced... or something else? 

Thanks for any help or suggested approach. 

Cheers,

--
   .     .   .   .   .  ....    .   .   .     ..     ..    .   .   .  .``.
   .`. .`.   .   . .`   .       .   .   .   .`     .`      .   .`. .  `.
   .  `  .   .   .`.    .``     .```.   .   .  ..  .  ..   .   .  `.    `.
   .     .   .   .  `.  ....    .   .   .    `..`   `..`   .   .   .  `..`
 


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to