Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Module suggestions for parsing query words (ala google)?

by BrowserUk (Patriarch)
on Sep 30, 2010 at 20:34 UTC ( [id://862852]=note: print w/replies, xml ) Need Help??


in reply to Module suggestions for parsing query words (ala google)?

Ostensibly, your "parser" could be as simple as:

$input = "name: jones location: ny";; %query = map{ split ':\s+' } $input =~ m[(\S+:\s+\S+)]g;; pp \%query;; { location => "ny", name => "jones" }

Or just:

$input = "name: jones location: ny";; %query = $input =~ m[(\S+):\s+(\S+)]g;; pp \%query;; { location => "ny", name => "jones" }

Do you need more sophistication than that?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Module suggestions for parsing query words (ala google)?
by pffan239 (Beadle) on Oct 01, 2010 at 12:24 UTC

    Thanks for your reply!

    That definitely a good start. at first, I didn't think that regex's would good enough.

    I didn't have it in my original post, but I had in mind that the query terms could be multiple words. ie:

    name: mike jones location: ny

    or perhaps, more explicitly:

    name: "mike jones" location: ny

    regardless, my regex fu should be good enough to get that figured out.

    I'll give this approach a shot and see how far I get.

      Something like:

      @inputs = ( "name: mike jones location: ny", 'name: "mike jones" location: ny', "name: jones location: ny" );; $re = qr[ (?: (\S+): \s* ) ["']? (.+?) ["']? (?=\s+\S+:|$) ]x;; %h = m[$re]g and pp $_, \%h for @inputs;; ("name: mike jones location: ny", { location => "ny", name => "mike jo +nes" }) ("name: \"mike jones\" location: ny", { location => "ny", name => "mik +e jones" }) ("name: jones location: ny", { location => "ny", name => "jones" })

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Wow!

        Above and beyond the call of duty. This is a tremendous help! Much appreciated.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://862852]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2026-02-16 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.