use strict; use warnings; use Parse::RecDescent (); my $szGrammar = <<'__END_OF_GRAMMAR__'; { use strict; use warnings; use constant DEBUG => 1; use Data::Dumper; sub AddToHash { print "MyParser->AddToHash(@_)\n" if (DEBUG); my ($this, $szVar, $szValue) = @_; $this->{Result}->{$szVar} = $szValue; } sub GetResult { print "MyParser->GetResult(@_)\n" if (DEBUG); my ($this) = @_; return $this->{Result}; } sub DumpResult { print "MyParser->DumpResult(@_)\n" if (DEBUG); my ($this) = @_; print Dumper($this->{Result}); } } test: expr(s) /^\Z/ expr: name '=' /\d+/ { $thisparser->AddToHash($item{name}, $item[-1]); } name: /\w+/ __END_OF_GRAMMAR__ Parse::RecDescent->PreCompile($szGrammar, 'MyParser') or die("Bad Grammar\n"); #### use strict; use warnings; use MyParser (); my $hParser = MyParser->new(); my $szCode = "x = 1\ny = 2\nz = 3"; $hParser->test($szCode) or die("Bad code\n"); $hParser->DumpResult();