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


In reply to Re^2: scope issues in Parse::RecDescent by citromatik
in thread scope issues in Parse::RecDescent by citromatik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":