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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: scope issues in Parse::RecDescent
by Corion (Patriarch) on Mar 22, 2011 at 12:21 UTC | |
by citromatik (Curate) on Mar 23, 2011 at 11:43 UTC | |
Re: scope issues in Parse::RecDescent
by jethro (Monsignor) on Mar 22, 2011 at 13:36 UTC |
Back to
Seekers of Perl Wisdom