http://www.perlmonks.org?node_id=304810

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

Hi,

I'm looking for a module that allows me to set a series of arbitrary criteria and produce a result :-)

for example:

if a b c > X but less than Y or possibly U or b c d > Z

the kicker is that each of the variables may have dozens or hundreds of values (parsed from multiple files) so the normal if/else is not feasible.

What I'm doing is taking partially statistical performance output from hundreds of 'instances' and producing semi-intelligent 'during the hours 1pm - 3pm, high usage and relatively high spinlocks in a particular cache but low utilization - consider partitioning cache to X and possibly reduce the size'.

in essence, I'm looking for an almost LISP-like rules engine. I haven't touched LISP for more than 20 years. I would prefer to have a perl based engine.

thanks

Jason L. Froebe

Replies are listed 'Best First'.
Re: Rules based Perl
by BrowserUk (Patriarch) on Nov 05, 2003 at 19:36 UTC

    Comparing single values against a list of values isn't too hard.

    use List::Util qw[ min max ]; if( $X < min( $a, $b, $c ) and $Y > max( $a, $b, $c ) or $Z < min( $b, $c, $d ) ) { # do something }

    The lists can equally be arrays of as many values as you need.

    Unfortunately, the example is incomplete. I couldn't find a state diagram for 'possibly' :)


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!
    Wanted!

      Couldn't 'possibly' be interpreted as 'or'? For instance, if I have 'b and c but possibly a', couldn't I also write that as 'a or (b and c)'? That way, the evaluation of a does not necessarily determine the truth of the entire staement, but it has the possibility of making the entire statement evalutate to true.

      thor

        Possibly:)


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        Hooray!
        Wanted!

Re: Rules based Perl
by boo_radley (Parson) on Nov 05, 2003 at 18:52 UTC
    if a b c > X but less than Y or possibly U or b c d > Z the kicker is that each of the variables may have dozens or hundreds of values (parsed from multiple files) so the normal if/else is not feasible.
    Have you seen Quantum::Superpositions? I bet any() and all() can help you collapse those tricky sets of decisions and values.
Re: Rules based Perl
by CombatSquirrel (Hermit) on Nov 05, 2003 at 18:57 UTC
    Have you had a look at the LISP module on CPAN yet?
    Cheers,
    CombatSquirrel.
    Entropy is the tendency of everything going to hell.
Re: Rules based Perl
by sauoq (Abbot) on Nov 05, 2003 at 20:23 UTC

    You might look at AI::ExpertSystem::Simple. I've never used it, so I can't say anything about how it might fit your needs.

    If I was doing this, I might use CLIPS rather than Perl. There is a learning curve, but CLIPS is really cool.

    Poking around, I noticed that someone started writing a Perl module for CLIPS integration. You can find it at http://www.discomsys.com/~mps/dnld/clips-stuff/. It looks like it has been neglected for quite some time though.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Rules based Perl
by Cody Pendant (Prior) on Nov 05, 2003 at 20:32 UTC
    Why not use some module that allows you to access data using SQL statements then dynamically build the statement?


    ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print
Re: Rules based Perl
by gjb (Vicar) on Nov 06, 2003 at 14:02 UTC

    If you don't mind a work around: there's an excellent rule engine in Java called Jess. You could access it from Perl using the Java module. The latter allows to create Java objects and treat them as if they were Perl.

    A book on Jess has recently been reviewed on slashdot as well as on developer.com. Jess is related to and mostly backward compatible with the CLIPS engine mentioned by sauoq.

    Hope this helps, -gjb-