Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

RE: How to write a nice rule base?

by reptile (Monk)
on Aug 30, 2000 at 02:57 UTC ( #30234=note: print w/ replies, xml ) Need Help??


in reply to How to write a nice rule base?

hmm... how about a suggestion on a different approach? You could put your rule base into a hash, with the 'action' possibilities as keys, storing a hashref with the 'sort' and 'msgid' etc. keys, like this (truncated) example:

my %RULES = ( 'post' => { 'msgid' => '^(\d+|new)$', 'data' => '...', }, 'edit' => { 'msgid' => '^(\d+|new)$', }, ..., }; my $allowed = $RULES{ $query->{'action'} }; foreach $key (keys %$query) { exists $allowed->{'key'} ? 1 : return 0; ... }

Or, since it seems pretty obvious there can be only one action type at a time, you could probably cascade the trinary operator, like so:

for ($query->{'action'}) { $allowed = /post/ ? { ... } : /edit/ ? { ... } : /delete/ ? { ... } : die "that action isn't supported"; }

or any variation you like there. The hash-based one is probably faster.

local $_ = "0A72656B636148206C72655020726568746F6E41207473754A"; while(s/..$//) { print chr(hex($&)) }


Comment on RE: How to write a nice rule base?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (15)
As of 2014-12-19 11:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (81 votes), past polls