I needed a simple way to test if a list of keywords (tags) had the required words, but one moment later, conditional operators other than AND were required. I didn't find a public module that satisfied my needs. Some of this was discussed in AND and OR on Regular Expressions.

I took my subs and group them in a module, then changed into objects (my first attempt in OOP) and worked nice.

Examples of use:

# Simple query (same as: +xxx -ppp -jjj): my $query = "xxx-(ppp,jjj)"; use Keywords; my $kw = Keywords->new(ignorecase => 1); $kw->prepare($query); # Simple test: print "Match!" if $kw->test($list_of_tags); # @ids has some keys %table: @ok = grep {$kw->test($table{$_}[$col])} @ids; # Same as before: @ok = $kw->grep_keys(map {$_ => $table{$_}[$col]} @ids); # Hash only has keywords lists: @ok = $kw->grep_keys(%tags); # When ids are full keywords: @ok = $kw->grep(@ids);

Now, I want to share my efforts and decided to upload this to CPAN, but I need to define or append to a namespace. I thought on Search::Keywords, but Keywords::Match might be a better one.

Hints for a proper namespace?

Hints for extra features? I'm thinking on set/get parms, reparse, sentences (when tags have more than one word), UTF8 (un)support...

Thanks!


In reply to RFC: A module to evaluate keywords expressions on tag lists. by vitoco

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.