Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you add a <code>use strict</code> to your script you'll get the fatal error <em>Can't use string ("1") as a HASH ref while "strict refs" in use at [the call to <code>merge_hash_refs</code>]</em>. It appears that the closures created by the <code>&lt;defer&gt;</code> directives are causing the contents of <code>@item</code> to be the ones when the production matched instead of the hashrefs eventually returned by the subrules. Removing the <code>&lt;defer&gt;</code> directives gives me this output:</p> <pre><code>$VAR1 = { 'stuff2' =&gt; 'stuff', 'stuff' =&gt; 'stuff' }; </code></pre> <p>Of course, this has the side effect that $::object is updated by successful <code>object</code> productions even if the higher level rules fail (including backtracking). I'd write it this way:</p> <pre><code>use strict; use warnings; use Parse::RecDescent; use Data::Dumper; my $parser = Parse::RecDescent-&gt;new(&lt;&lt;'EOT'); event_function: object_list ':' event_list(?) ';' { $return = $item[1]; } object_list : &lt;leftop: object ',' object&gt; { $return = { map { %$_ } @{$item[1]} }; } object : '/' /[a-z0-9_][a-z0-9_]*/ '/' '...' { $return = { $item[2] =&gt; 'stuff' }; } | /[a-z0-9_][a-z0-9_]*/ { $return = { $item[1] =&gt; 'stuff' }; } # stub, don't know what this should be event_list : /[^;]+/ EOT my %object; while (&lt;DATA&gt;) { my $x = $parser-&gt;event_function($_); next unless $x; # merge objects into master list while (my ($k, $v) = each %$x) { $object{$k} = $v; } } print Dumper \%object; __DATA__ stuff, stuff2: pre-operation event = {foo1, foo2}; stuff3, stuff4: ; </code></pre> <p>The output is:</p> <pre><code>$VAR1 = { 'stuff2' =&gt; 'stuff', 'stuff3' =&gt; 'stuff', 'stuff' =&gt; 'stuff', 'stuff4' =&gt; 'stuff' }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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