You might use $thisparser->{local} to collect stuff along the way (as opposed to using package variables):
#!/usr/bin/env perl use strict; use warnings; use Parse::RecDescent; use Data::Dumper; my $grammar = <<'END'; foo: word(s) word: /\S+/ { push @{$thisparser->{local}}, lc $item[1]; $return = uc $item[1]; } END my $parser = Parse::RecDescent->new($grammar); my $what = $parser->foo("Foo bAr baZ"); print Dumper $what, $parser->{local}; __END__ $VAR1 = [ 'FOO', 'BAR', 'BAZ' ]; $VAR2 = [ 'foo', 'bar', 'baz' ];
The docs say that ... the use of $this...->{local} is always safe. You will have to reset this field if you plan to call the same parser multiple times and you don't want each run to add its items to those of the previous runs. And, of course, nothing prevents you from using local for storing more complicated data structures.

This said, I suggest that you read Corion's advices again. It seems like you're trying to mix parsing and evaluation, which might not be the wisest thing to do.

perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Io ho capito... ma tu che hai detto?

In reply to Re: Parse grammar via RecDescent parser by polettix
in thread Parse grammar via RecDescent parser by the_dark_lord

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.