The "Found = in Conditional" warning was not from the tertiary, but the logical and. Since you are not really doing a logical test, but just combining statements, I would use the comma operator, here.
$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|subject|expire)$'), ($allowed{msgid} = '^(\d*|all)$')) : 1; $query->{action} eq "short" ? (($allowed{sort} = '^(author|date|subject|expire)$'), ($allowed{msgid} = '^(\d+|all)$')) : 1; foreach $key (keys %$query){ exists $allowed{$key} ? 1 : return 0; return 0 if $query->{$key}!~/$allowed{$key}/; 1; }

Now, that said, here's another way to handle this:

# Map keys to coderefs (used sort of like a switch statement) my %ActionMap = (post => sub{ $allowed{msgid} = '^(\d+|new)$'; $allowed{data} = '^(([^|+]*[^|]+.*\|){4}[^|+]*[^|]+.*)$'; }, edit => sub{ $allowed{msgid} = '^(\d+|new)$'; }, delete => sub{ $allowed{msgid} = '^(\d+)$'; }, long => sub{ $allowed{sort} = '^(author|date|subject|expire)$'; $allowed{msgid} = '^(\d*|all)$'; }, short => sub{ $allowed{sort} = '^(author|date|subject|expire)$'; $allowed{msgid} = '^(\d+|all)$'; }); # "Call" the coderef matching the "switch" value $ActionMap{$query->{action}}->(); for my $key (keys %$query){ return 0 unless exists $allowed{$key} && $query->{$key} =~ /$allowed +{$key}/; }
Notes:

Russ
Brainbench 'Most Valuable Professional' for Perl


In reply to RE: rule base (comma operator / 'switch' construct) by Russ
in thread How to write a nice rule base? by TGI

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.