Greetings all, I'm trying to parse a config file for a system that is a braced config file. But the config has nested braces. For instance:
bob { ed { larry { rule5 { option { disable-server-response-inspection no; } tag [ some_tag ]; from [ prod-L3 ]; to [ corp-L3 ]; source [ any ]; destination [ any ]; source-user [ any ]; category [ any ]; application [ any ]; service [ any ]; hip-profiles [ any ]; log-start no; log-end yes; negate-source no; negate-destination no; action allow; log-setting orion_log; } rule6 { option { disable-server-response-inspection no; } tag [ some_tag ]; from [ prod-L3 ]; to [ corp-L3 ]; source [ any ]; destination [ any ]; source-user [ any ]; category [ any ]; application [ any ]; service [ any ]; hip-profiles [ any ]; log-start no; log-end yes; negate-source no; negate-destination no; action allow; log-setting orion_log; } } } }

I can't figure out how to get that test to display correctly. I wrapped it in pre but the links are text that was wrapped in brackets. ANyway...

It's a lot of nesting. I have 1000's of these rules to parse plus other subsections to parse through. I started with Config::Scoped hoping that it would be able to help me but it seems to struggle with nested blocks:

GetOptions ( "pancfg=s" => \$pan_cfg, "outfile=s" => \$outfile ) or die("Error in command line arguments. Arguments:\n\t--pancfg + = Pan config file to read.\n\t--outfile = Output file for parsed dat +a."); #Open the config file and attempt to parse it. $cs = Config::Scoped->new( file => $pan_cfg, warnings => $warnings, ); $cfg_hash = $cs->parse;

That code block errors with:

Invalid decl item: Was expecting parameter or macro or comment or warning but found "mgt-config { " instead at

that "mgt-config { " is one of the subsections that occurs in the config file. I'm sorta struggling to find a decent way to do this. Can anyone offer any advice or better solutions?

In reply to Parsing a config file with braces and nested braces by IamtheGorf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.