I actually worked with dhcp.conf back in '98 or so. We were converting extensive BOOTP tables to a dhcp.conf. I don't remember the spec any, though. ok, enough reminescing. :)

You could use Parse::RecDescent. A start would be:

my $grammar = <<'__END_OF_GRAMMAR__'; { use strict; use warnings; } parse : item(s?) /\Z/ { $item[1] } item : subnet | option subnet : SUBNET IP_ADDR NETMASK IP_ADDR subnet_blk { [ @item[0,2,4,5] ] } subnet_blk : option(s?) option : OPTION option_list { [ $item[0], @{$item[2]} ] } option_list : ... # Reserved Words # ============== #SUBNET : IDENT { $item[1] eq 'subnet' ? $item[1] : undef } #NETMASK : IDENT { $item[1] eq 'netmask' ? $item[1] : undef } #OPTION : IDENT { $item[1] eq 'option' ? $item[1] : undef } SUBNET : /subnet(?![a-zA-Z-9_])/ NETMASK : /netmask(?![a-zA-Z-9_])/ OPTION : /option(?![a-zA-Z-9_])/ # Tokens # ====== IDENT : /[a-zA-Z][a-zA-Z-9_]*/ IP_ADDR : /\d+\.\d+\.\d+\.\d+/ __END_OF_GRAMMAR__

Update: Optimized reserved words.


In reply to Re: Parsing Config File with Multi-line Elements by ikegami
in thread Parsing Config File with Multi-line Elements by pileofrogs

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.