if ($not_in_shift) { if ($current || !$past) { print "Register for shift\n"; } } else { if ($current) { print "Confirm in shift\n"; print "Remove from shift\n"; } if ($past) { print "Confirm in shift\n"; } } #### #!/usr/bin/perl -w use strict; # These can be filled by some function my %conditions = ( Current => 1, Not_in_shift => 1, Past => 0, ); # Menu item to print if any set of conditions satisfies my %menu = ( 'Add Self' => [ "Current,Not_in_shift", "!Past,Not_in_shift", ], ); # No need to touch this stuff ever for my $item ( keys %menu ) { for my $set ( @{$menu{$item}} ) { my $result = 1; for my $condition ( split(/,/,$set) ) { # Negating condition is a convenient thing to have if (substr($condition,0,1) eq '!') { substr($condition,0,1,''); ($result &&= !$conditions{$condition}) || last; } else { ($result &&= $conditions{$condition}) || last; } } if ($result) { add_menu_item($item); last; } } } # Whatever we want to do with the menu item sub add_menu_item { my $item = shift; print "$item\n"; }