Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Conditional Elimination

by bart (Canon)
on Aug 30, 2011 at 11:53 UTC ( [id://923192]=note: print w/replies, xml ) Need Help??


in reply to Conditional Elimination

Funny you should ask this now, as I just saw a very similar question on StackOverflow but for PHP, yesterday (posted 23 hours ago). Do you, by accident, know each other?

Anyway, what I'd think of is to store a simple expression, as text, in the database. You could do it in Perl and use eval. Or, my preference, you could write the expressions in a simpler language (which first of all doesn't have the '$' for the variables) than Perl, for example Javascript (and C and ... zillions of other languages), possibly even extended. For example your code could better, IMHO, be rewritten as:

a eq "A" && p in (88, 89, 90, 91)

Then all you have left to do is write a simple expression parser/evaluator, and I just happen to have written one, once. I've even converted it to Perl, here: Operator Precedence Parser. I see it doesn't parse functions (with parameters) (yet), which would be useful for implementing in(...), but that's not too hard to add. I might do that as an exercise, later today. <pEdit When I think about it, using/parsing "in" as a function is not right: it's actually an operator with a scalar on the LHS and a list on the RHS. A function with arguments would look similar, but would be used in a different position (as an expression instead of as an operator) so it ought to be parsed, and processed, differently.

Replies are listed 'Best First'.
Re^2: Conditional Elimination
by Solo (Deacon) on Aug 30, 2011 at 13:15 UTC
    write the expressions in a simpler language

    I agree. 50 conditions calls for a domain-specific language to separate the building of the conditions from their execution. Decision::ParseTree looks like another good place to start.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-18 20:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found