http://www.perlmonks.org?node_id=894775

citromatik has asked for the wisdom of the Perl Monks concerning the following question:

Hi all

Another one with Parse::RecDescent:

If you want to get back a list of tokens from a grammar you have to do something like this:

use strict; use warnings; use Data::Dumper use Parse::RecDescent; use vars qw/@tokens/; my $p6 = Parse::RecDescent->new(q( letter : /\w/ character : letter { push @main::tokens, $item{letter}; } Format : character Format )); $p6->Format('abc'); die "Invalid pattern" unless (defined $p6); print Dumper \@tokens;

Is there any way to avoid the use of global variables for achieving this? I would like to feed the grammar with different input strings

Thanks in advance!

citromatik