in reply to How do I return a hash from Parse::RecDescent?

Hmm, here's one way:

... test: expr(s) /^\Z/ { my %hash; @hash{keys %$_} = values %$_ for @{$item{"expr(s)"}}; return \%hash; } ...

Prints:

$HASH1 = { x => 1, y => 2, z => 3 };

Is there anything "better"?


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: How do I return a hash from Parse::RecDescent?
by ikegami (Patriarch) on Sep 22, 2006 at 05:29 UTC

    I know you just copied the OP, but return \%hash; should be just \%hash.

    His return $item{"expr(s)"} should be just $item{"expr(s)"}.

    P::RD actions (i.e. code blocks in curlies) are placed in a do, not a sub. Since return shouldn't be used to exit a do, return shouldn't be used to exit a P::RD action.