Tricky Merge task in Perl - Pls help

D

dbone

I don't even know where to start with this one. I have several files
that I need to merge into a master file. Both files have the same
syntax but I need to merge the second within the master in the correct
place. This is tricky because the second file may need to be merged
several bracket levels deep. The example below has it merged at one
level deep.

In the example below the master might look like:

-------------- <snip> -----------
cmd configure pvc "Enable SNMP atm pvc traps"
{
attr alsoCR
cmd configure interval "minimum period between successive traps"
{
cmd configure <1-3600> "minimum period between successive traps
(in seconds)"
{
attr alsoCR
cmd configure fail-interval "minimum period for storing the
failed timestamp"
{
cmd configure <0-3600> "minimum period for storing the
failed timestamp (in seconds)"
}
}
}
}
-------------- <snip> -----------


The file to be merged might look like:

-------------- <snip> -----------
cmd configure fail-interval "minimum period for storing the failed
timestamp"
{
cmd configure <0-3600> "minimum period for storing the failed
timestamp (in seconds)"
}
-------------- <snip> -----------


The idea is to merge the two for the result below.


-------------- <snip> -----------
cmd configure pvc "Enable SNMP atm pvc traps"
{
attr alsoCR
cmd configure fail-interval "minimum period for storing the failed
timestamp"
{
cmd configure <0-3600> "minimum period for storing the failed
timestamp (in seconds)"
}
cmd configure interval "minimum period between successive traps"
{
cmd configure <1-3600> "minimum period between successive traps
(in seconds)"
{
attr alsoCR
cmd configure fail-interval "minimum period for storing the
failed timestamp"
{
cmd configure <0-3600> "minimum period for storing the
failed timestamp (in seconds)"
}
}
}
}
-------------- <snip> -----------

Please help me get this one figured out.

thanks,
dave
 
J

John Bokma

dbone said:
I don't even know where to start with this one. I have several files
that I need to merge into a master file. Both files have the same
syntax but I need to merge the second within the master in the correct
place. This is tricky because the second file may need to be merged
several bracket levels deep. The example below has it merged at one
level deep.

In the example below the master might look like:

-------------- <snip> -----------
cmd configure pvc "Enable SNMP atm pvc traps"
{
attr alsoCR
cmd configure interval "minimum period between successive traps"
{
cmd configure <1-3600> "minimum period between successive
traps
(in seconds)"
{
attr alsoCR
cmd configure fail-interval "minimum period for storing
the
failed timestamp"
{
cmd configure <0-3600> "minimum period for storing the
failed timestamp (in seconds)"
}
}
}
}

:
:

I would almost say:

- convert it to XML (do able)
- then handle it as XML (easy)
- and convert it back (easy)

Since in order to do anything with it you have to parse it, the XML idea
is not that weird.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top