Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Parse grammar via RecDescent parser

by polettix (Vicar)
on May 19, 2016 at 13:21 UTC ( [id://1163477]=note: print w/replies, xml ) Need Help??


in reply to Parse grammar via RecDescent parser

You might use $thisparser->{local} to collect stuff along the way (as opposed to using package variables):
#!/usr/bin/env perl use strict; use warnings; use Parse::RecDescent; use Data::Dumper; my $grammar = <<'END'; foo: word(s) word: /\S+/ { push @{$thisparser->{local}}, lc $item[1]; $return = uc $item[1]; } END my $parser = Parse::RecDescent->new($grammar); my $what = $parser->foo("Foo bAr baZ"); print Dumper $what, $parser->{local}; __END__ $VAR1 = [ 'FOO', 'BAR', 'BAZ' ]; $VAR2 = [ 'foo', 'bar', 'baz' ];
The docs say that ... the use of $this...->{local} is always safe. You will have to reset this field if you plan to call the same parser multiple times and you don't want each run to add its items to those of the previous runs. And, of course, nothing prevents you from using local for storing more complicated data structures.

This said, I suggest that you read Corion's advices again. It seems like you're trying to mix parsing and evaluation, which might not be the wisest thing to do.

perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Io ho capito... ma tu che hai detto?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-05-23 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found