henka has asked for the wisdom of the Perl Monks concerning the following question:

Hello, Given the following code, I'd like to step through the data structure for each item to build another structure. Any help would be appreciated.
#!/usr/bin/perl use strict; use warnings; use Search::QueryParser; use Data::Dumper; my $s = 'site:www.cnn.com term2 -term3 +"my phrase" +(term4 term5)'; my $qp = new Search::QueryParser; my $query = $qp->parse($s) or die "Error in query : " . $qp->err; print "QUERY: $s\n"; print Dumper($query);
Produces:
$VAR1 = { '-' => [ { 'value' => 'term3', 'op' => ':', 'field' => '' } ], '' => [ { 'value' => 'www.cnn.com', 'op' => ':', 'field' => 'site' }, { 'value' => 'term2', 'op' => ':', 'field' => '' } ], '+' => [ { 'quote' => '"', 'value' => 'my phrase', 'op' => ':', 'field' => '' }, { 'value' => { '' => [ { 'value' => 'term4', 'op' => ':', 'field' => '' }, { 'value' => 'term5', 'op' => ':', 'field' => '' } ] }, 'op' => '()', 'field' => '' } ] };

Replies are listed 'Best First'.
Re: Stepping through a Search::QueryParser data structure
by planetscape (Chancellor) on Jul 15, 2006 at 09:31 UTC
      thanks, planetscape, I'll check it out - and yes, that's basically what I want to do; just get the data out in a recursive fashion with a hook so I can do things to each element.

        Excellent. So glad I could be of help. Thanks for letting me know. :-)

        planetscape