Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: scope issues in Parse::RecDescent

by citromatik (Curate)
on Mar 23, 2011 at 11:43 UTC ( #894982=note: print w/ replies, xml ) Need Help??


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


Comment on Re^2: scope issues in Parse::RecDescent
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://894982]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2015-07-04 02:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls