The main problem for me is that the

> configuration file lacks a formal syntax specification

IMHO it's too dangerous to be simply done with a fancy regex.

You need validation to catch wrong assumptions and errors in the input.

For instance it's unclear

I'd personally go for maintainability over speed then.

Like writing an iterator which returns each "VIEW" as a nested data structure.

Like this you can find and report errors and create a tidied version.

Actually it's not too difficult to define your own grammar as a DSL of subs

my $iterator = block start => qr/^VIEW \s+ (?<name>\w+)/x , stop => qr/^END_VIEW/ , hash => sub { entry "RECORD"; group "FIELD", array => sub { entries "FIELD" }; entry "INTERVAL"; } ;

group() would be a special case of block() with

start => qr/^ \s* FIELD \s+ \( \s* $/x , stop => qr/^ \s* \) \s* $/x,

Inside those DSL subs I'd use an nextline() iterator, which does single readlines and handles empty lines and comments and returns undef if the stop condition of the upper level is met.

And you might consider using a q_entry() sub for automatic unquoting of "quoted" entries. hence you are free to dynamically adapt to unknown conditions.

NB This is untested code, I started to implement it but don't wanna spend my free Sunday on it, sorry ;-)

HTH! :)

Update

if you wanna go this way, I'll share more insights.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice


In reply to Re: Parsing and editing a configuration file by LanX
in thread Parsing and editing a configuration file by eyepopslikeamosquito

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.