in reply to Re: Checking lots of conditions...ORed and ANDed
in thread Checking lots of conditions...ORed and ANDed

My above code has a nasty habit of allowing things it shouldn't depending on the order of the conditions. Assuming that 'disallow' rules trump 'allow' rules, here is a quick fix.

sub get_menu_items { my ($rules,@conditions) = @_; my %results; for my $cond ( @conditions ) { next unless exists $rules->{$cond}; for $item ( @{$rules->{$cond}->{allows}} ) { $results{$item}++; } } for my $cond ( @conditions ) { next unless exists $rules->{$cond}; for $item ( @{$rules->{$cond}->{disallows}} ) { delete $results{$item}; } } return keys %results; }
--Solo
--
You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.