GrandFather has asked for the wisdom of the Perl Monks concerning the following question:
I have a test grammar that returns an array of hashes:
use Parse::RecDescent; use Data::Dump::Streamer; my $grammar = q{ test: expr(s) /^\Z/ {return $item{"expr(s)"};} expr: name '=' /\d+/ { $return = {$item{name} => $item[-1]}; 1; } name: /\w+/ }; my $parser = new Parse::RecDescent ($grammar); Dump ($parser->test ("x = 1\ny = 2\nz = 3"));
Prints:
$ARRAY1 = [ { x => 1 }, { y => 2 }, { z => 3 } ];
but I'd like a simple hash:
$HASH1 = { x => 1, y => 2, z => 3 };
For some reason my brain has frozen up and I just can't get the syntax right. What am I missing? (I'd rather Parse::RecDescent return the hash than fix it later.)
|
|---|