in reply to Parse::RecDescent: autoactions and precompiled grammars

Thank you for pointing out that I can precompile the grammar into a module. This gave me a nearly four fold speed increase.

To answer your question... I'm assuming you are using the command line approach to precompilation suggested in the perldoc:

perl -MParse::RecDescent - grammar Yet::Another::Grammar
If I read the docs correctly, you could write a little script instead. Then you can control all of the flag variables:
use Parse::RecDescent; $::RD_AUTOACTION = ...; Parse::RecDescent->Precompile( $grammar_string, 'Your::Namespace::GrammarModule' );
Phil

Replies are listed 'Best First'.
Re^2: Parse::RecDescent: autoactions and precompiled grammars
by ikegami (Patriarch) on Apr 10, 2006 at 15:19 UTC
    Just to confirm (since the docs only mention this working with new and the parent wasn't confident in his answer), here's a working example of $::RD_AUTOACTION being set when Precompile is called:
    use Data::Dumper qw( Dumper ); use Parse::RecDescent (); { local $::RD_AUTOACTION = q { [@item] }; Parse::RecDescent->Precompile( 'parse: /a/ /b/ /c/', 'Grammar' ) or die("Bad grammar\n"); } { # Normally, this would be in another file. require Grammar; my $parser = Grammar->new(); print(Dumper($parser->parse('a b c'))); }

    outputs

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

    If you comment out autoaction, the output is

    $VAR1 = 'c';
Re^2: Parse::RecDescent: autoactions and precompiled grammars
by braden (Novice) on Apr 10, 2006 at 16:00 UTC

    Yes, I was using the command line approach.

    Thanks!