http://qs321.pair.com?node_id=894982


in reply to Re: scope issues in Parse::RecDescent
in thread scope issues in Parse::RecDescent

It seems that you can define "top level" actions and define variables in them. So this would do the trick:

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

Outputs:

$VAR1 = [ 'a', 'b', 'c' ];

citromatik