I hope you don't mind if I go beyond what you asked about. (In fact, I won't even touch that since it's already been addressed.)
use strict; use warnings; use Parse::RecDescent; use Data::Dumper; my $config_parser = Parse::RecDescent->new(<<'__END_OF_GRAMMAR__'); { # These pragmas affect the whole parser. use strict; use warnings; sub check_ip_nums { my ($ip) = @_; return !(grep $_ > 255, split /./, $ip); } sub dequote { my ($s) = @_; for ($s) { s/^"//; s/"\z//; s/\\(.)/$1/sg; return $_; } } } parse : line(s) /\Z/ { $item[1] } line : '' # Skip blank lines. <skip:'[ \\t]*'> # Don't treat newlines as whitespac +e. key_value /\n/ <skip: $item[2]> { $item[3] } key_value : server | key server : IDENT { $item[1] eq 'bind-server' } IP { [@item[0,3]] + } key : IDENT { $item[1] eq 'tsig-key' } filename { [@item[0, +3]] } filename : QSTRING | BAREWORD # Tokens IDENT : /[-\w]+/ QSTRING : /"(?:[^"\\]|\\.)*"/ { dequote($item[1]) } BAREWORD : /[^"\\\s]+/ IP : # This could be done more readably, but # the more is done by the regexp, the # faster it's going to be. A lot faster. /(?:[1-9][0-9]{0,2}|0)\.(?:[1-9][0-9]{0,2}|0)\.(?:[1- +9][0-9]{0,2}|0)\.(?:[1-9][0-9]{0,2}|0)/ { check_ip_nums($item[1]) ? $item[1] : undef } __END_OF_GRAMMAR__ print Dumper $config_parser->parse(<<'__END_OF_CONFIG__'); bind-server 127.0.0.1 tsig-key "/etc/bind/rndc.key" __END_OF_CONFIG__

In reply to Re: Parse::RecDescent trouble by ikegami
in thread Parse::RecDescent trouble by ribasushi

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.