Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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 making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-08-22 06:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (147 votes), past polls