Hi, I am looking for some help with Parse::RecDescent. I wrote the following code to parse a string containing several parameters for an SQL style search. The goal is to create a tree I can traverse from the bottom up so that I can execute the code in order. I started with a simple example but if you look at the commented out input you will see where I hope to end up.
# my $input = "(cvtype='problem') and (problem_description match '*' +) and ((problem_synopsis match 'FCSIM') or (problem_synopsis match 'A +TTE')) and (create_time>time('06/01/2014 0:00:00')) and (create_time< +time('09/30/2014 0:00:00'))"; my $input = "(cvtype='problem') and (problem_description match '*') +"; print "Text: $input\n"; my $grammar = q{ startrule: expr expr: operand operation(s?) { $return = @{$item[2]} ? { $item[2], $item[1]} : $item[1]} operation: /and | or/ operand { $return = { $item[1], $item[2] }} operand: '(' expr ')' { $return = $item[2] } | term { $item[1]} term: /[\w\s=><\/:"'\*_]+/ }; my $parser = Parse::RecDescent->new($grammar); my $result = $parser->startrule($input) or die "Could Not Parse! +\n"; print Dumper $result;
The results look like this:
$VAR1 = { 'ARRAY(0xa102e8)' => 'cvtype=\'problem\'' }; I expected the results to look something like this: $VAR1 = { { 'cvtype=\'problem\'' } { and } { problem_description match \'*\' } };

I know I am missing something fundamental. But I can’t seem to find it. I don't have any Idea where that array ref is coming from. Any help you can provide would be helpful.
P.S. I also have the Debug output but it's huge. Please let me know if you think I should post it.
Thank You,
DevM


In reply to Can I get some rules help with PARSE::RECDESCENT by DevM

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.