TGI has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing a program that I would like to have use a succint and easy to read rule format. The solution I cam up with makes -w scream bloody murder, though. Is there anything wrong with this approach? Any better ideas?
I just love to play with the ?: stuff! I tried several if{} approaches, but none were as readable. My error logs keep filling up with: "Found = in conditional, should be == at program.pl line 254." Any way to get this ignored (if it's not going to shoot me in the foot)?
Here's my sample:
$allowed{action} = 'post|edit|delete|long|short'; $query->{action} eq "post" ? ($allowed{msgid} = '^(\d+|new)$') && ( +$allowed{data} = '^(([^|+]*[^|]+.*\|){4}[^|+]*[^|]+.*)$'):1; $query->{action} eq "edit" ? $allowed{msgid} = '^(\d+|new)$':1; $query->{action} eq "delete" ? $allowed{msgid} = '^(\d+)$':1; $query->{action} eq "long" ? ($allowed{sort} = '^(author|date|subj +ect|expire)$') && ($allowed{msgid} = '^(\d*|all)$'):1; $query->{action} eq "short" ? ($allowed{sort} = '^(author|date|subj +ect|expire)$') && ($allowed{msgid} = '^(\d+|all)$'):1; foreach $key (keys %$query) { exists $allowed{$key} ? 1 : return 0; return 0 if $query->{$key}!~/$allowed{$key}/; 1; }
BTW, I iterate over the $allowed hash to
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: How to write a nice rule base?
by reptile (Monk) on Aug 30, 2000 at 02:57 UTC | |
|
RE: rule base (comma operator / 'switch' construct)
by Russ (Deacon) on Aug 30, 2000 at 02:47 UTC | |
|
RE: How to write a nice rule base?
by adamsj (Hermit) on Aug 30, 2000 at 02:26 UTC |