Note that there are some explanatory texts on larger screens.

plurals
  1. POParse::RecDescent - getting information from it
    text
    copied!<p>I'm working with the <a href="http://search.cpan.org/perldoc?Parse::RecDescent" rel="nofollow noreferrer">Parse::RecDescent</a> parser in Perl, and I seem to have the most terrible time getting information from it. The information readily available online does not seem to have non-trivial examples.</p> <p>Here is the code:</p> <pre><code>event_function: object_list ':' event_list ';' &lt;defer: { #item is a special character with Parse::Recdescent. print Dumper($item{object_list}); $return = $item[1]; } &gt; | object_list ':' ';' &lt;defer: { print Dumper($item{object_list}); $return = $item[1]; } &gt; </code></pre> <p>Here is the output</p> <pre><code>PS W:\developers\paulnathan\rd_dir&gt; perl parser.pl testfile $VAR1 = 4; $VAR1 = 8; PS W:\developers\paulnathan\rd_dir&gt; </code></pre> <p>The input file parses correctly.</p> <pre><code>stuff, stuff2: pre-operation event = {foo1, foo2}; </code></pre> <p>It <em>should</em> be outputting a hash keyed by "stuff", "stuff2".</p> <p>Thoughts?</p> <p>edit:</p> <pre><code>object_list : object ',' object_list &lt;defer: { my $retval = (); $retval = ::merge_hash_refs($item[1], $item[3]); $return = $retval; } &gt; | object &lt;defer: { #print Dumper($item{object}); $return = $item{object}; } &gt; object : '/' /[a-z0-9_][a-z0-9_]*/ '/' '...' &lt;defer: { $::objects-&gt;{$item[2]} = "stuff"; $return = $::objects; } &gt; | /[a-z0-9_][a-z0-9_]*/ &lt;defer: { $::objects-&gt;{$item[1]} = "stuff"; $return = $::objects; } &gt; </code></pre> <p>edit2: Merge_hash_refs, just in case. :-)</p> <pre><code>#takes two hash references. sub merge_hash_refs { my($ref1, $ref2) = @_; my $retref = (); while( my ($k, $v) = each %$ref1 ) { $retref-&gt;{$k} = $v; } while( my ($k, $v) = each %$ref2 ) { $retref-&gt;{$k} = $v; } return $retref; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload