This seems like a good place to mention that you'll need to place use statements in a startup block to take advantage of any Perl 5.10-isms.
Code slightly modified from an example in Advanced Perl 2nd Edition:
use Modern::Perl;
use Parse::RecDescent;
my $grammar = q{
{ use Modern::Perl }
GameTree : "(" Sequence GameTree(s?) ")"
Sequence : Node(s)
Node : ":" Property(s) { say "I saw a node!" }
Property : PropIdent PropValue(s)
PropIdent : /[A-Z]+/
PropValue : { extract_bracketed($text, '[ ]') }
};
my $sgf_parser = Parse::RecDescent->new($grammar);
undef $/;
my $sgf = <DATA>;
say $sgf_parser->GameTree($sgf);
__DATA__
(:GM[1]FF[4]AP[CGoban:2]ST[2]RU[Japanese]
PW[Honinbo Shuwa]PB[Yasuda Shusaku]
WR[7d]BR[5d]
:B[qd]:W[dc]:B[pq]:W[oc]:B[cp]:W[qo]
:B[pe]C[This is the famous Shusaku opening".])
I could be wrong, of course. This is how I got the thing to run with say in the action, though.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|